Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

筛选法+数组模拟链表,360+MS,求优化

Posted by Panamera at 2014-04-10 15:12:43 on Problem 2262
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator