poj2635 The Embarrassed Cryptographer
来源:互联网 发布:中国体育彩票关注软件 编辑:程序博客网 时间:2024/06/05 21:57
Description The young and very promising cryptographer Odd Even has
implemented the security module of a large system with thousands of
users, which is now in use in his company. The cryptographic keys are
created from the product of two primes, and are believed to be secure
because there is no known method for factoring such a product
effectively. What Odd Even did not think of, was that both factors in
a key should be large, not just their product. It is now possible that
some of the users of the system have weak keys. In a desperate attempt
not to be fired, Odd Even secretly goes through all the users keys, to
check if they are strong enough. He uses his very poweful Atari, and
is especially careful when checking his boss’ key.Input The input consists of no more than 20 test cases. Each test case
is a line with the integers 4 <= K <= 10100 and 2 <= L <= 106. K is
the key itself, a product of two primes. L is the wanted minimum size
of the factors in the key. The input set is terminated by a case where
K = 0 and L = 0.Output For each number K, if one of its factors are strictly less than
the required L, your program should output “BAD p”, where p is the
smallest factor in K. Otherwise, it should output “GOOD”. Cases should
be separated by a line-break.
首先用线性筛求出1e6以内的质数,然后用所有不超过l的质数验证。
这样问题就转化成了大整数取模。逐位加上数,边加边取模即可。
#include<cstdio>#include<cstring>const int mx=1e6;int prm[1000010],tot;bool have[1000010];char s[110];void make(){ for (int i=2;i<=mx;i++) { if (!have[i]) prm[++tot]=i; for (int j=1;j<=tot&&i*prm[j]<=mx;j++) { have[i*prm[j]]=1; if (i%prm[j]==0) break; } }}int main(){ int i,j,k,l,m,n,p,q,x,y,z; bool flag; make(); while (scanf("%s%d",s+1,&l)&&l) { m=strlen(s+1); flag=0; for (i=1;i<=tot&&prm[i]<l;i++) { n=0; for (j=1;j+2<=m;j+=3) n=(n*1000+(s[j]-'0')*100+(s[j+1]-'0')*10+s[j+2]-'0')%prm[i]; if (j==m-1) n=(n*100+(s[j]-'0')*10+s[j+1]-'0')%prm[i]; if (j==m) n=(n*10+s[j]-'0')%prm[i]; if (n==0) { flag=1; printf("BAD %d\n",prm[i]); break; } } if (!flag) printf("GOOD\n"); }}
- poj2635 The Embarrassed Cryptographer
- POJ2635 The Embarrassed Cryptographer
- poj2635 The Embarrassed Cryptographer
- POJ2635 The Embarrassed Cryptographer
- POJ2635 The Embarrassed Cryptographer
- POJ2635----The Embarrassed Cryptographer
- poj2635 The Embarrassed Cryptographer
- POJ2635 The Embarrassed Cryptographer (同余)
- POJ2635--The Embarrassed Cryptographer--大数取模
- POJ2635 The Embarrassed Cryptographer 简单数论
- (POJ2635)The Embarrassed Cryptographer(大数取模)
- POJ2635——The Embarrassed Cryptographer
- The Embarrassed Cryptographer poj2635 (大数取模)
- poj2635--The Embarrassed Cryptographer(数论篇1,大数取模)
- poj2635 The Embarrassed Cryptographer(高精度 同余取模)
- poj2635——The Embarrassed Cryptographer(高精度取模)
- pku2635 The Embarrassed Cryptographer
- POJ235 The Embarrassed Cryptographer
- LightOJ - 1045 Digits of Factorial
- 四大组件之 Activity
- Android studio R文件报错解决
- map和collection是统一等级的接口
- 十八哥Mysql笔记之提高篇
- poj2635 The Embarrassed Cryptographer
- UVA129 Krypton Factor
- Activity中的onCreate方法不执行问题
- c#中实现的万能变量类
- 解决Eclipse中DDMS的Emulator Control灰色无法使用的问题
- Android 项目中嵌入 ReactNative 模块
- HDU 5862Counting Intersections (思维+树状数组)
- AVL树解析
- 23种设计模式 第二部分 结构模式(3) 代理模式