HDU1262

打素数表

View Code
 1 #include<stdio.h>

 2 #include<string.h>

 3 const int maxn = 10010;

 4 int shu[ maxn ],prime[ maxn ];

 5 void get_prime( ){

 6     for( int i=1;i<maxn;i+=2 ) shu[ i ]=1;

 7     for( int i=0;i<maxn;i+=2 ) shu[ i ]=0;//0 is stand for not prime

 8     shu[ 1 ]=0;

 9     shu[ 2 ]=1;

10     for( int i=3;i<maxn;i+=2 ){

11         if( shu[i]==1 ){

12             int t,delta;

13             delta=i*2;

14             t=delta+i;

15             while( t<maxn ){

16                 shu[ t ]=0;

17                 t+=delta;

18             }

19         }

20     }

21     /*

22     prime[1]=2;

23     int cnt=2;

24     for( int i=3;i<maxn;i++ ){

25         if( shu[i]==1 ){

26             prime[ cnt++ ]=i;

27         }

28     }

29     */

30 }

31 int main(){

32     int m;

33     get_prime();

34     while( scanf("%d",&m)==1 ){

35         for( int i=m/2;;i-- ){

36             if( shu[i]==1&&shu[m-i]==1 ){

37                 printf("%d %d\n",i>(m-i)?(m-i):i,i>(m-i)?i:(m-i));

38                 break;

39             }

40         }

41     }

42     return 0;

43 }

 

你可能感兴趣的:(HDU)