POJ 2635 The Embarrassed Cryptographer

Source: Internet
Author: User

The Embarrassed authentication Limit: 2000 MS Memory Limit: 65536 KTotal Submissions: 10450 Accepted: 2752 DescriptionThe young and very promising cryptographer Odd Even has implemented the security module of a large system with limits 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 has tively. what Odd Even did not think of, was that both factors in a key shocould 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 es Pecially 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 of the 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 shocould output "BAD p", where p is the smallest factor in K. otherwise, it shoshould output "GOOD ". cases shoshould be separated by a line-break.Sample Input143 10143 20667 20667 302573 302573 400 0 Sample OutputGOODBAD 11 GOODBAD 23 GOODBAD 31 SourceNordic 2005 this question, determine the idea of continuous Wa, looking at the helpless data, I opened a small array. The general idea is that enumeration is close to 700ms. [cpp] # include <stdio. h> # include <string. h> # include <Math. h> int a [1000001]; char s1 [101]; _ int64 B [30]; int main () {_ int64 I, j, n, m, t, l, weishu; _ int64 s; memset (a, 0, sizeof (a); for (I = 2; I <= 1000000; I ++) {if (a [I] = 0) {for (j = 2; I * j <= 1000000; j ++) {a [I * j] = 1 ;}} while (scanf ("% s % I64d", s1, & m )! = EOF) {l = strlen (s1); for (I = 0; I <= L-1; I ++) {if (s1 [I]! = '0') {break;} if (I = l & m = 0) {break;} memset (B, 0, sizeof (B )); for (I = 0, j = 0, s = 0; I <= L-1; I ++) {B [j] = B [j] * 10 + (s1 [I]-'0'); s ++; if (I + 1) % 9 = 0 | I = L-1) {j ++; weishu = s; s = 0 ;}} n = j; for (I = 2; I <= m-1; I ++) {if (a [I] = 0) {for (j = 0, s = 0; j <= n-1; j ++) {if (j! = N-1) {s = s * 1000000000 + B [j];} else {for (t = 1; t <= weishu; t ++) {s = s * 10;} s + = B [j];} s = s % I;} if (s = 0) {break ;}}} if (I = m) {www.2cto.com printf ("GOOD \ n");} else {printf ("BAD % I64d \ n", I) ;}} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.