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

用C++交RE了n多次,用G++居然瞬间AC ,无语。。。

Posted by ss_aries at 2013-06-16 11:46:12 on Problem 2552
虽然只是水过,但是好纠结,无语。。。
代码:
#include<iostream>
#include<cstdio>
using namespace std;
const int N=35005;
bool v[N+50];
int a[3050];
int main()
{
    int i,j;
    for(i=1;i<N;i++)
    {
        v[i]=1;
    }
    for(i=2;i<N/2;i++)
    {
        int k=0;
        j=i+1;
        if(v[i])
        while(j<N)
        {
            if(!v[j++])  continue;
            k++;
            if(k==i)
            {
                v[j-1]=0;
                k=0;
            }
        }
    }
    j=1;
    for(i=2;i<N;i++)
    {
        if(v[i])  a[j++]=i;
    }
    //cout << j<< endl;
    int n;
    while(scanf("%d",&n)!=-1)
    {
        if(n==0)  break;
        cout << a[n] << endl;
    }
    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