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

样例过了,但为什么WA呢?那位牛人帮帮忙啊

Posted by ldld at 2009-12-18 19:41:50 on Problem 2635
#include <iostream>
#include <cstring>
#include <algorithm>
#define max 1000005
using namespace std;

int primenumber = 0, primelist[max], isnotprime[max], l, a[35], q, la;
char k[105];

void prime()
{
    long long i, j;
	memset(isnotprime, 0, sizeof(isnotprime));
    isnotprime[0] = 1;
    isnotprime[1] = 1;
    for(i=2; i < max; i++)
    {
        if(!isnotprime[i])
        {
            primelist[primenumber++] = i;
            if(i * i > max) continue;
            for(j = i * i; j < max; j += i)
            {
                isnotprime[j] = 1;
            }
        }
    }
}

void zhuanhua()
{
    memset(a, 0, sizeof(a));
    int length, i, t;
    length = strlen(k);
    for(i = 0; i < length; i++)
    {
        t = (length - i + 3) / 4 - 1;
        a[t] = a[t] * 10 + k[i] - '0';
    }
    la = (length + 3) / 4;
}

int mod(int m)
{
    int temp = 0, i;
    for(i = la - 1; i >= 0; i--)
    {
        temp = temp * 1000 % m + a[i] % m;
    }
    return temp % m;
}

int main()
{
    int i, temp;
    prime();
    while(scanf("%s%d", k, &l), k[0] != '0' && l)
    {
        temp = 0;
        zhuanhua();
        for(i = 0; primelist[i] < l; i++)
        {
            if(!mod(primelist[i]))
            {
                printf("BAD %d\n", primelist[i]);
                temp = 1;
                break;
            }
        }
        if(!temp)
            printf("GOOD\n");
    }
    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