poj_2635 The Embarrassed Cryptographer(高精度求模)
2016-11-30 22:06
295 查看
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 userskeys, to check if they are strong enough. He uses his very poweful Atari, and is especially careful when checking his boss' key.InputThe 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 ofthe factors in the key. The input set is terminated by a case where K = 0 and L = 0.OutputFor 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
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 14367 | Accepted: 3926 |
![](http://poj.org/images/2635_1.jpg)
143 10 143 20 667 20 667 30 2573 30 2573 40 0 0Sample Output
GOOD BAD 11 GOOD BAD 23 GOOD BAD 31
题目输入的整数数值达到了10^100,得用数组来保存,十进制保存的话会超时,用千进制可以减少运算时间,即将数字1234567890保存为
a[] = {890, 567, 234, 1}。之后高精度求模。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <stack>#include <bitset>#include <queue>#include <set>#include <map>#include <string>#include <algorithm>#define FOP freopen("data.txt","r",stdin)#define FOP2 freopen("data1.txt","w",stdout)#define inf 0x3f3f3f3f#define maxn 1000010#define4000mod 1000000007#define PI acos(-1.0)#define LL long longusing namespace std;bool vis[maxn];int prime[maxn];int cot;void sieve(int n){int m = (int)sqrt(n+0.5);for(int i = 2; i <= m; i++) if(!vis[i])for(int j = i*i; j <= n; j += i) vis[j] = 1;for(int i = 2; i <= n ; i++) if(!vis[i]) prime[cot++] = i;}char s[110];int a[40];int n;int b;bool judge(int *a, int n, int b){int res = 0;for(int i = n-1; i >= 0; i--){res = (res * 1000 + a[i]) % b;}return res == 0;}int main(){//FOP;sieve(1000010);while(~scanf("%s%d", s+1, &b) && b){n = 0;memset(a, 0, sizeof(a));int len = strlen(s+1), i;for(i = len - 2; i >= 1; i -= 3){a[n++] = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + s[i+2] - '0';}i += 2;for(int j = 1; j <= i; j++){a= a* 10 + s[j] - '0';if(j == i) n++;}int ans = 0;for(i = 0; prime[i] < b; i++){if(judge(a, n, prime[i])){ans = prime[i];break;}}if(ans == 0) printf("GOOD\n");else printf("BAD %d\n", ans);}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 [高精度求余+同余模定理]【数论】
- poj2635——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
- 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