Sicily1231. The Embarrassed Cryptography
2015-03-18 23:07
309 查看
1231. The Embarrassed Cryptography
Constraints
Time Limit: 2 secs, Memory Limit: 32 MB
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 theproduct 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 wantedminimum 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 separatedby 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// Problem#: 1231 // Submission#: 3294427 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ // All Copyright reserved by Informatic Lab of Sun Yat-sen University #include <stdio.h> #include <iostream> #include <vector> #include <string> #include <stack> #include <iomanip> #include <algorithm> #include <queue> #include <functional> #include <map> #include <string.h> using namespace std; const int primeNum = 1000005; bool isNotPrime[primeNum]; int prime[100000]; int pNum = 0; void makePrime() { for (int i = 2; i < primeNum; i++) { if (!isNotPrime[i]) { prime[pNum++] = i; for (int j = 2 * i; j < primeNum; j += i) { isNotPrime[j] = true; } } } } bool isMod(string & key, int p) { int r = 0, s = key.size(); for (int i = 0; i < s; i++) { r = (r * 10 + key[i] - '0') % p; } return r == 0; } int main() { std::ios::sync_with_stdio(false); makePrime(); while (1) { string key; int least, i; cin >> key >> least; if (key == "0" && least == 0) break; for (i = 0; i < pNum && prime[i] < least; i++) { if (isMod(key, prime[i])) { cout << "BAD " << prime[i] << endl; break; } } if (prime[i] >= least) cout << "GOOD" << endl; } return 0; }
相关文章推荐
- sicily 1231. The Embarrassed Cryptography
- sicily 1231 The Embarrassed Cryptography
- Sicily 1231. The Embarrassed Cryptography【高精度取余】
- sicily 1231. The Embarrassed Cryptography
- sicily 1231. The Embarrassed Cryptography
- 1231. The Embarrassed Cryptography(求两个素数积)
- 1231 The Embarrassed Cryptography
- 1231. The Embarrassed Cryptography
- 1231. The Embarrassed Cryptography
- POJ 2635 The Embarrassed Cryptographer 线性筛+高精度取模
- == The History of Cryptography/ Algorithms/ conceptual modeling ==
- Sicily 1401. Children of the Candy Corn
- poj 2635 The Embarrassed Crypto…
- POJ2635 - The Embarrassed Cryptographer【打表+高精度】
- [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)
- Sicily 1155. Can I Post the lette
- Sicily 4423. Calculate the Sum
- POJ The Embarrassed Cryptographer 2635 (数论)
- sicily 1070. Hansel and Grethel
- [Cryptography]The Vigenere Cipher