blob: f2c24357845ff2999f21ae32ad589f5c722e9015 (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#define MAX 3000000
int notPrime[MAX]={0};
void genprimes(int n)
{
notPrime[0]=1;
notPrime[1]=1;
int i,j;
for (i=2;i<=n;++i){
if (!notPrime[i]){
for (j=i*2;j<=n;j+=i){
notPrime[j]=1;
}
}
}
}
int main()
{
int a,b,n;
int product=0,longest=0;
genprimes(MAX);
for (a=-999;a<=999;a+=2){
for (b=-997;b<=997;b+=2){
if (notPrime[abs(b)])
continue;
for (n=0;;++n){
int t=(n+a)*n+b;
if (notPrime[abs(t)]){
if (n>longest){
longest = n;
product = a*b;
}
break;
}
}
}
}
printf("%d\n",product);
return 0;
}
|