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 }

 

转载于:https://www.cnblogs.com/xxx0624/archive/2013/02/18/2915227.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值