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

这个样子竟然会超时?

Posted by cyb19950118 at 2014-08-12 09:01:13 on Problem 3511
#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long

using namespace std;

int prim[200000]={2,3,5};
int k =3;

void is_prim()
{
    int i, j;
    int flag, step = 2;

    for(i=7;i<=1000000;i+=step)
    {
        step = 6-step;
        flag = 1;
        for(j=0;prim[j]*prim[j]<=i;j++)
            if(i%prim[j] == 0){
                flag = 0;
                break;
            }
        if(flag)
            prim[k++] = i;
    }
}

int main()
{
    int L, U;
    int i, ans1, ans2, j;

    is_prim();
    while(scanf("%d %d",&L,&U),L!=-1||U!=-1){
        ans1 = ans2 = 0;
        for(i=0;L>prim[i];i++);
        for(j=i;prim[j]<=U;j++)
        {
            printf("%d \n",prim[j]);
            if((prim[j]-1)%4 == 0|| prim[j]==2)
                ans2++;
            ans1++;
        }
        printf("%d %d %d %d\n",L,U,ans1,ans2);
    }
    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