标签:des style blog http color io strong for
Description
Input
Output
Sample Input
10 20 11 19 100 1000 -1 -1
Sample Output
10 20 4 2 11 19 4 2 100 1000 143 69
#include<stdio.h> #include<string.h> #define N 1000005 int prime[100005]; int flag[1000005]; int e; void getP() // 素数打表,找出素数存栈 { int i, j; e = 0; memset(flag, 0, sizeof(flag) ); //标记初始化 for ( i=2; i<N; i++) { if ( flag[i]==0 ) { prime[e++] = i; //进栈 } for ( j=0; j<e && i*prime[j]<N; j++ ) { flag[ i * prime[j] ] = 1; } } } int main() { int l,u,x,y; getP(); int i; while(scanf("%d %d",&l,&u)) { if(l==-1 && u==-1) break; x=0; y=0; for( i=0; i<e; i++) { if(prime[i]>=l && prime[i]<=u ) { x++; if(prime[i]%4==1) { y++; } } if(prime[i]>u) break; } if(l<=2 && u>=2) { y++; } printf("%d %d %d %d\n",l, u, x, y ); } return 0; }
Fermat’s Chirstmas Theorem (素数打表的),布布扣,bubuko.com
Fermat’s Chirstmas Theorem (素数打表的)
标签:des style blog http color io strong for
原文地址:http://www.cnblogs.com/yspworld/p/3900513.html