poj 2635
2014-08-06 22:20
176 查看
The Embarrassed Cryptographer
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.
Sample Input
Sample Output
Source
Nordic 2005
K是两个质数的积,L是个范围,若能找到一个小于L的质数是K的约数,那么BAD同时输出该质数,否则GOOD
题目很明朗了,就是要怎么处理大数了,自己看代码吧,理解。
AC代码:
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 12076 | Accepted: 3224 |
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.
Sample Input
143 10 143 20 667 20 667 30 2573 30 2573 40 0 0
Sample Output
GOOD BAD 11 GOOD BAD 23 GOOD BAD 31
Source
Nordic 2005
K是两个质数的积,L是个范围,若能找到一个小于L的质数是K的约数,那么BAD同时输出该质数,否则GOOD
题目很明朗了,就是要怎么处理大数了,自己看代码吧,理解。
AC代码:
#include<iostream> #include<string> #include<stdio.h> #include<cstring> using namespace std; string s; int prime[500100]; int isprime[1000100]; int num[110]; int lenp,L; void sieve(int n){ //筛素数 int i,j; for(i=0;i<=n;i++) isprime[i]=1; lenp=0; for(i=2;i<=n;i++){ if(isprime[i]){ prime[lenp++]=i; for(j=2*i;j<=n;j+=i) isprime[j]=0; } } } int main(){ sieve(1000000); while(cin>>s>>L){ if(s[0]=='0' && L==0) break; int l=s.length(); //大数转化为数字,每三位存在num里 int a=l/3; int b=l%3; int i,j,k; for(i=0;i<=a;i++) num[i]=0; if(b){ for(i=0;i<b;i++) num[0]=num[0]*10+s[i]-'0'; } j=b; for(i=1;i<=a;i++){ for(k=0;k<3 && j<l;j++,k++){ num[i]=num[i]*10+s[j]-'0'; } } int sucess=0; int ans; for(j=0;j<lenp && prime[j]<L;j++){ int ans=0; for(i=0;i<=a;i++){ ans=(ans*1000+num[i])%prime[j]; } if(ans==0){ //判断能否被整除 sucess=1; k=j; break; } } if(sucess) cout<<"BAD "<<prime[k]<<endl; else cout<<"GOOD"<<endl; } return 0; }
相关文章推荐
- POJ 2635 The Embarrassed Cryptographer
- poj2635
- POJ 2635 The Embarrassed Cryptographer
- POJ2635 The Embarrassed Cryptographer 简单数论
- poj 2635 The Embarrassed Cryptographer
- POJ 2635.The Embarrassed Cryptographer
- E - The Embarrassed Cryptographer POJ - 2635
- poj 2635 The Embarrassed Cryptographer
- poj-2635-The Embarrassed Cryptographer
- POJ2635——The Embarrassed Cryptographer
- POJ 2635 高精度MOD 和 乱搞的进制转换
- poj 2635
- poj2635
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- poj-2635
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635(同余定理)
- poj解题报告——2635
- POJ 2635 The Embarrassed Cryptographer尴尬的译解密码者