hdu1262寻找素数对<数论>

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1262

View Code
 1 #include <stdio.h>

 2 #include <stdlib.h>

 3 #include <math.h>

 4 int a[10005]={0};

 5 void fun(  )

 6 {

 7     a[1]=a[0]=1;

 8     for( int i=4; i<10005; i+=2 )

 9         a[i]=1;

10     for( int i=3; i <= ( int )sqrt( 10005 ); i+=2 )

11     {

12         if(a[i]==0)

13             for( int j=i*i; j<10005; j += ( i+i ) )    

14             {

15                 a[j]=1;    

16             }

17     }      

18 }

19 

20 int main()

21 {

22     fun( );

23     int n;

24     while( scanf( "%d", &n ) != EOF )

25     {

26         for( int i=n/2; i>1; i-- )

27         {

28             if( a[i]==0 && a[n-i]==0 )

29             {

30                     printf( "%d %d\n", i, n-i );

31                 break;    

32             }        

33         }    

34     }

35     return 0;

36 }

 

你可能感兴趣的:(HDU)