-
Notifications
You must be signed in to change notification settings - Fork 0
/
day 27
50 lines (39 loc) · 852 Bytes
/
day 27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
bool isPrime(int x)
{
if (x <= 1)
return false;
for (int factor = 2; factor*factor <= x; factor++)
if (x % factor == 0)
return false;
return true;
}
int main() {
int limit;
unsigned int consecutive = 0;
cin>>limit;
if (limit < 0)
limit = -limit;
int bestA = 0;
int bestB = 0;
for (int a = -limit; a <= +limit; a++)
for (int b = -limit; b <= +limit; b++)
{
unsigned int length = 0;
while (isPrime(length * length + a * length + b))
length++;
if (consecutive < length)
{
consecutive = length;
bestA = a;
bestB = b;
}
}
cout << bestA << " " << bestB << std::endl;
return 0;
}