Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
筛选法+数组模拟链表,360+MS,求优化#include<stdio.h> #define MAX_N 1000100 int prime[MAX_N]; void init() { int tmp = 2 ; for(int i=3;i<MAX_N;i +=2) { if(prime[i]) continue; for(int j=i+i;j<MAX_N;j +=i) prime[j] = 1 ; prime[tmp] = i ; tmp = i ; } prime[tmp] = -1; } int main() { init(); int n; while(scanf("%d",&n)&&n) { for(int i=2;i<=n/2;i = prime[i]) { if(prime[n-i]!=0&&prime[n-i]!=1) { printf("%d = %d + %d\n",n,i,n-i); break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator