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 zuo_bj2004 at 2005-10-07 16:00:43 on Problem 2635
#include<stdio.h>
#define MAX 1000000
int num[102];
char ch[105];
long K,test;
int tag;
int prime[MAX]={1,1,0};

void Prime()
{
	long i, j;
    for (i=2; i<=MAX; i++)
		if (prime[i] == 0)
			for (j=2*i; j<=MAX; j+=i)
				prime[j] = 1;

}

int zhengchu()
{
	long temp;
	int i;
	temp=0;
	for(i=0;i<tag;i++)
	{
		temp=temp*10+num[i];
	    temp%=test;
	}
	
	if(temp==0)
		return 1;
	return 0;
}

int main()
{
	int i;
	Prime();
	scanf("%s%ld",ch,&K);
	while(ch[0]&&K)
	{
		int flag=0;
		for(i=0;ch[i]>='0';i++)
			num[i]=ch[i]-'0';
		tag=i;
		for(test=2;test<K;test++)
			if((!prime[test])&&zhengchu())
			{
				flag=1;
				printf("BAD %ld\n",test);
				break;
			}
		if(!flag)
			printf("GOOD\n");
		scanf("%s%ld",ch,&K);
	}
	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