43 lines
805 B
C
43 lines
805 B
C
|
#include <stdio.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
int gcd(int a, int b);
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
int lim = 1500000;
|
||
|
int i, n, m, p, c, odd;
|
||
|
char sieve[lim + 1];
|
||
|
|
||
|
for(i = 0; i <= lim; ++i){
|
||
|
sieve[i] = 0;
|
||
|
}
|
||
|
odd = c = 0;
|
||
|
for(n = 2; n <= (sqrt(2*lim + 1) - 1)/ 2; ++n){
|
||
|
for(m = odd + 1; m < n && m <= (lim / 2*n) - n; m += 2){
|
||
|
if(gcd(n, m) == 1){
|
||
|
p = 2*n * (n + m);
|
||
|
for(i = p; i <= lim; i += p){
|
||
|
sieve[i] += 1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
odd = !odd;
|
||
|
}
|
||
|
for(i = 0; i <= lim; i += 2){
|
||
|
if(sieve[i] == 1){
|
||
|
++c;
|
||
|
}
|
||
|
}
|
||
|
printf("%d\n", c);
|
||
|
}
|
||
|
|
||
|
int gcd(int a, int b)
|
||
|
{
|
||
|
int c;
|
||
|
while (a != 0){
|
||
|
c = a; a = b%a; b = c;
|
||
|
}
|
||
|
return b;
|
||
|
}
|