-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem_27.c
45 lines (40 loc) · 845 Bytes
/
problem_27.c
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 <math.h>
static int is_prime( unsigned long p )
{
if( p < 2 ) {
return 0;
}
if( p == 2 ) return 1;
if( p % 2 == 0 ) return 0;
unsigned long i;
for( i = 3; i <= sqrt( p ); i+=2 ) {
if( p % i == 0 ) {
return 0;
}
}
return 1;
}
int main( )
{
int a, b, n;
int res = 0, res_a, res_b;
for( b = 2; b < 1000; b++ ) {
if( !is_prime(b) ) continue;
for( a = -999; a < 999; a += 2 ) {
int v = b;
n = 0;
do {
v += 2*n + 1 + a;
if( v < 0 ) break;
n++;
} while( is_prime(v) );
if( res < n + 1 ) {
res = n + 1;
res_a = a;
res_b = b;
}
}
}
printf( "Answer: %d\n", res_a*res_b );
}