Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪里错了呀????#include<stdio.h> #include<string.h> #define M 1000000 int prime[100000]; char isprime[1000001]; int div(int *a,int b,int k) { int i; int m=0; // for(i=k;i>=1;i--) //printf("%d ",a[i]); //printf("\n"); for(i=k;i>=1;i--) { m=m*1000+a[i];m%=b; } return m; } int main() { int i,j,k,m,n,a[200],c[200]; char ch[120]; prime[1]=2; prime[2]=3; k=2; for(i=5;i<=M;i+=2) { for(j=2;prime[j]*prime[j]<=i;j++) { if(i%prime[j]==0)goto loop; } k++;prime[k]=i;isprime[i]=1; loop:; } while(1) { scanf("%s%d",ch,&n); int flag=0; for(i=0;i<strlen(ch);i++) a[i]=ch[i]-'0'; if(ch[0]=='0'&&n==0)break; int len=strlen(ch); k=0; while(len>=3) { k++; c[k]=a[len-1]+a[len-2]*10+a[len-3]*100; len-=3; } if(len>0) { if(len==2){k++;c[k]=a[0]*10+a[1];} else{k++;c[k]=a[0];} } m=k; /* printf("%d\n",m); for(i=1;i<=m;i++) printf("%d ",c[i]); printf("\n"); */ for(k=2;k<n;k++) {if(isprime[k]) { int re=div(c,k,m); if(re==0){flag=1;goto end;} } } end:; if(flag)printf("BAD %d\n",k); else printf("GOOD\n"); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator