poj 2635 The Embarrassed Cryptographer
2016-09-24 22:28
330 查看
【分析】
线性筛+大整数取模
注意在跑整数的时候不要逐位更新,否则会T,我借鉴了yhx的方法三个三个更新,这样刚好不超出int范围
【代码】
线性筛+大整数取模
注意在跑整数的时候不要逐位更新,否则会T,我借鉴了yhx的方法三个三个更新,这样刚好不超出int范围
【代码】
//poj 2635 The Embarrassed Cryptographer #include<iostream> #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> #define M(a) memset(a,0,sizeof a) #define fo(i,j,k) for(i=j;i<=k;i++) using namespace std; const int mxn=1e6; char k[105]; int pri[mxn+5],l; bool vis[mxn+5]; inline int read() { int x=0,f=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void shai() { int i,j; fo(i,2,mxn) { if(!vis[i]) pri[++pri[0]]=i; fo(j,1,pri[0]) { if(i*pri[j]>mxn) break; vis[i*pri[j]]=1; if(i%pri[j]==0) break; } } } int main() { int i,j; shai(); while(scanf("%s",k+1)) { l=read(); if(!l) return 0; int len=strlen(k+1); bool flag=0; for(i=1;i<=pri[0] && pri[i]<l;i++) { int now=0; for(j=1;j<=len-2;j+=3) now=(now*1000+100*(k[j]-'0')+10*(k[j+1]-'0')+k[j+2]-'0')%pri[i]; if(j==len-1) now=(now*100+10*(k[len-1]-'0')+k[len]-'0')%pri[i]; else if(j==len) now=(now*10+k[len]-'0')%pri[i]; if(now==0) { flag=1; printf("BAD %d\n",pri[i]); break; } } if(!flag) printf("GOOD\n"); } return 0; }
相关文章推荐
- POJ 2635 The Embarrassed Cryptographer
- poj 2635 The Embarrassed Cryptographer(数论)
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- The Embarrassed Cryptographer--POJ 2635
- poj2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer(JAVA)
- POJ-2635 The Embarrassed Cryptographer 万进制+素数筛选
- POJ 2635 The Embarrassed Cryptographer 高精度
- POJ 2635 The Embarrassed Cryptographer 大数模
- POJ 2635 The Embarrassed Cryptographer(整数刷新,千进制取模)
- POJ 2635 The Embarrassed Cryptographer
- poj-2635-The Embarrassed Cryptographer
- POJ-2635 The Embarrassed Cryptographer 大数取模
- poj 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- poj 2635 The Embarrassed Cryptographer
- poj2635 The Embarrassed Cryptographer
- POJ 2635, The Embarrassed Cryptographer