Created
June 9, 2015 17:47
-
-
Save johnboker/3ff1cb234fa307968a76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
long isprime(long n); | |
long n2n41(long n); | |
int primepct[10001]; | |
int main(int argc, char **argv) | |
{ | |
long a, b, i, ip; | |
int notprime, prime; | |
for(i = 0; i < 10001; i++) | |
{ | |
primepct[i] = 0; | |
} | |
while (scanf("%ld %ld", &a, &b) != EOF) | |
{ | |
for(i = a; i <= b; i++) | |
{ | |
if(primepct[i-1]==0) | |
{ | |
if(isprime(n2n41(i))==0) | |
{ | |
prime++; | |
primepct[i-1] = 1; | |
} | |
else | |
{ | |
notprime++; | |
primepct[i-1] = -1; | |
} | |
} | |
else | |
{ | |
if(primepct[i-1]==1) | |
{ | |
prime++; | |
} | |
else | |
{ | |
notprime++; | |
} | |
} | |
} | |
printf("%.2f\n", floor(((double)prime/(prime+notprime))*10000+.5)/100); | |
notprime = 0; | |
prime=0; | |
} | |
return 0; | |
} | |
long n2n41(long n) | |
{ | |
return n*n+n+41; | |
} | |
long isprime(long n) | |
{ | |
long i = 3; | |
long sqn = 0; | |
while (n%2==0) | |
{ | |
n /= 2; | |
return 1; | |
} | |
sqn = (sqrt(n))+1; | |
while (i <= sqn) | |
{ | |
if ((n%i)==0) | |
{ | |
n /= i; | |
return 1; | |
} | |
else | |
{ | |
i += 2; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment