poj2635(素数表)
来源:互联网 发布:邱少云违背生理学知乎 编辑:程序博客网 时间:2024/06/05 16:02
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.
143 10143 20667 20667 302573 302573 400 0
GOODBAD 11GOODBAD 23GOODBAD 31
//Memory Time//624K 1235MS /*此题借鉴的http://blog.csdn.net/lyy289065406/article/details/6648530这是原作者地址*/#include<iostream>#include<string.h>using namespace std;const int Range=1000100; //打表不能只打到100W,素数表中最大的素数必须大于10^6int Kt[10000]; //千进制的Kint L;int prime[Range+1];/*素数组打表*/void PrimeTable(void){int pNum=0;prime[pNum++]=2;for(int i=3;i<=Range;i+=2) //奇偶法{bool flag=true;for(int j=0;prime[j]*prime[j]<=i;j++) //根号法+递归法if(!(i%prime[j])){flag=false;break;}if(flag)prime[pNum++]=i;}return;}/*高精度K对p求模,因数检查(整除)*/bool mod(const int* K,const int p,const int len){int sq=0;for(int i=len-1;i>=0;i--) //千进制K是逆序存放sq=(sq*1000+K[i])%p; //同余模定理if(!sq) //K被整除return false;return true;}int main(void){PrimeTable();char K[10000];while(cin>>K>>L && L){memset(Kt,0,sizeof(Kt));int lenK=strlen(K);for(int i=0;i<lenK;i++) //把K转换为千进制Kt,其中Kt局部顺序,全局倒序{ //如K=1234567=[ 1][234][567] ,则Kt=[567][234][1 ]int pKt=(lenK+2-i)/3-1;Kt[pKt]=Kt[pKt]*10+(K[i]-'0');}int lenKt=(lenK+2)/3;bool flag=true;int pMin=0; //能整除K且比L小的在prime中的最小素数下标while(prime[pMin]<L) //枚举prime中比L小的素数{if(!mod(Kt,prime[pMin],lenKt)){flag=false;cout<<"BAD "<<prime[pMin]<<endl;break;}pMin++;}if(flag)cout<<"GOOD"<<endl;}return 0;}
0 0
- poj2635(素数表)
- (POJ2635)The Embarrassed Cryptographer <高精度求模(千进制表示) + 同余模定理 + 素数打表>
- poj2635 同余定理 + 素数筛法
- poj2635
- poj2635
- poj2635
- poj2635
- poj2635
- poj2635
- poj2635
- poj2635
- POJ2635
- poj2635-大进制转化+同余定理+素数筛选
- POJ2635 The Embarrassed Cryptographer (同余)
- poj2635(大整数求余)
- 2016 小灶1 F (POJ2635)
- poj2635 The Embarrassed Cryptographer(高精度 同余取模)
- poj2635——The Embarrassed Cryptographer(高精度取模)
- UVA 1103 Ancient Messages dfs
- ArcGIS Python API获取以及对比landsat数据
- float的影响
- POJ2828 Buy Tickets(线段树,单点更新)
- jQuery来了--进行CSS操作的方法(添加/删除类),CSS()方法
- poj2635(素数表)
- 第八周 bfs
- 二分查找
- HDU1005 Number Sequence
- 基于活动选择问题来分析动态规划和贪心算法
- ffmpeg学习(一)
- Swing中Graphics绘制图片,图片使用随机背景色,随机字符串
- 开发JPA环境搭建
- static关键字