The Embarrassed Cryptographer POJ 2635 数论之高精度求模(同余模定理+千进制)
来源:互联网 发布:asp微信支付v3源码 编辑:程序博客网 时间:2024/06/02 18:08
The Embarrassed Cryptographer
Time Limit: 2000MSMemory Limit: 65536KTotal Submissions: 11344Accepted: 3022
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.
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.
Sample Input
143 10143 20667 20667 302573 302573 400 0
Sample Output
GOODBAD 11GOODBAD 23GOODBAD 31
Source
Nordic 2005
这个题目我觉得是非常有挑战性的,本来我看到第二个数是10^6,还是挺开心的,可以
不过我提交了就立刻呵呵了,第一个数太大了,longlong在取模是会出错的,所以我们
要用高精度求模的办法!!!
高精度求模:
123456是10进制的,因为每一位就一个数,那我们要计算它%t时,用同余模定理时
我们要1%t得出的sa,(sa*10+2)%t=sa;然后接着循环最后一位就是我们最终求的余数,
122%11=1,1%11=1;(1*10+2)%11=1;(1*10+2)%11=1;与我们最终求的结果相同,
但是我们的数太大了,会浪费很多时间,所以我们要用千进制来做,也就是说这必须
【123】【456】,但是我们求的时候用数组求必须注意次序,这个好说,这个求千进制
程序是很经典的,我也是借鉴了大神的思路!!!
#include<iostream>#include<cstdio>#include<cstring>#define M 10000040using namespace std;int prime[M];bool visit[M];int count;int q[100000];void table(){ memset(visit,true,sizeof(visit));int num = 0;int i;int j;for (int i = 2; i <= M; ++i){if (visit[i] == true){num++;prime[num] = i;}for (int j = 1; ((j <= num) && (i * prime[j] <= M)); ++j){visit[i * prime[j]] = false;if (i % prime[j] == 0) break;}}for(i=0;i<=M;i++){ if(prime[i]) count++;}}int mod(int q[],int t,int len){ int sq=0; int i; for(i=len-1;i>=0;i--) sq=(sq*1000+q[i])%t; if(!sq) return 0; return 1;}int main(){ int i,j,k,t; char n[100000]; int m; table(); int flag=0; while(cin>>n>>m) { if(m==0) break; flag=0; int a; int len=strlen(n); memset(q,0,sizeof(q)); for(i=0;i<len;i++) { j=(len+2-i)/3-1; q[j]=q[j]*10+(n[i]-'0'); } len=(len+2)/3; for(i=1;prime[i]<m;i++) { if(!mod(q,prime[i],len)) { flag=1; a=prime[i]; break; } } if(flag==0) printf("GOOD\n"); else { printf("BAD %d\n",a); } } return 0;}
- The Embarrassed Cryptographer POJ 2635 数论之高精度求模(同余模定理+千进制)
- 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(素数筛 + 同余模定理)
- poj The Embarrassed Cryptographer(大数取模)(同余模定理)
- [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)
- poj 2635 The Embarrassed Cryptographer (同余定理,筛选法)
- poj2635The Embarrassed Cryptographer(同余模+素数筛选+高精度求模)
- POJ 2635 The Embarrassed Cryptographer(千进制 高精度取模)
- POJ 2635 The Embarrassed Cryptographer (同余线性方程+素数筛)
- POJ 2635 The Embarrassed Cryptographer (同余问题)
- poj_2635 The Embarrassed Cryptographer(高精度求模)
- linux作业2答案
- 笔试小细节
- 惰性空间分配 lazy space allocation
- 用EM求解GMM的简单理解
- java源文件的编码格式问题
- The Embarrassed Cryptographer POJ 2635 数论之高精度求模(同余模定理+千进制)
- hiredis使用注意事项
- 20130925-电影精典台词
- 封装read、write、accept、connect函数,实现超时操作。
- MyEclipse代码辅助提示功能消失恢复
- 往数据库里存数时乱码,页面显示乱码
- 好吧,上篇是是单向的这篇是双向的
- Ubuntu命令行下安装,卸载软件包的过程
- linux校时-ntpd和ntpdate