-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem_46.c
43 lines (36 loc) · 882 Bytes
/
problem_46.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
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 10000000
static int sieve_init( unsigned int *sieve, unsigned int n )
{
unsigned int i, j;
memset( sieve, 1, ( n + 1 ) * sizeof( unsigned int ) );
sieve[0] = 0;
sieve[1] = 0;
for( i = 2; i <= sqrt( n ); i++ ) {
if( sieve[ i ] ) {
for( j = 2 * i; j <= n; j += i ) {
sieve[ j ] = 0;
}
}
}
}
int main( )
{
unsigned int *sieve = malloc( sizeof( int ) * ( N + 1 ) );
sieve_init( sieve, N );
unsigned int res;
unsigned int n = 3, i;
while( ( n += 2 ) < N ) {
if( sieve[n] ) continue;
for( i = n - 1; i > 0; i-- ) {
if( !sieve[i] ) continue;
double x = sqrt( ( n - i ) / 2 );
if( x == (unsigned int) x ) break;
}
if( i == 0 ) break;
}
printf( "Answer: %d\n", n );
}