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 |
用10进制tle,换成1000终于过了,860ms,代码未加优化,还是混些的有点乱#include<iostream> #include <cstring> #include <cmath> #include <cstdio> using namespace std; char num[10001]; int L,sum,t,cnt,number[101]; #define MAX 1000100 int prime[MAX]; bool a[MAX]; void Prime() { int num = 0, i, j; for(i = 2; i < MAX; ++i) { if(!(a[i])) prime[num++] = i; for(j = 0; (j<num && i*prime[j]<MAX); ++j) { a[i*prime[j]] = 1; if(!(i%prime[j])) break; } } } bool judge(int x) { int s=0; for(int i=cnt/3;i>=0;--i) { s=(s*1000+number[i])%x; } if(s==0)return true; else return false; } int main() { Prime(); while(scanf("%s%d",&num,&L)!=EOF) { if(L==0)break; cnt=strlen(num); int tail=cnt-1; for (int i=0;i<=cnt/3;++i) { number[i]=num[tail]-'0'+(num[tail-1]-'0')*10+(num[tail-2]-'0')*100; tail-=3; if(tail==-1)break; else if(tail==0) { number[++i]=num[tail]-'0'; break; } else if(tail==1) { number[++i]=(num[tail]-'0'+(num[tail-1]-'0')*10); break; } } int i=0,ans=0; while(prime[i]<L) { sum=0,t=0; if(judge(prime[i])) { ans=prime[i]; break; } ++i; } if(ans)cout<<"BAD "<<ans<<endl; else cout<<"GOOD\n"; cnt=0; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator