# 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 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
GOOD
GOOD


#include <stdio.h>
#include <memory.h>
int prime[80000];
int count;

void init() {
int visited[1000005];
memset(visited, true, sizeof(visited));
for (int c = 2; c < 1000005; ++c)
if (visited[c])
for (int d = c + c; d < 1000005; d += c)
visited[d] = false;

count = 0;
for (int c = 2; c < 1000005; ++c)
if (visited[c])
prime[count++] = c;
}

int main()
{
init();
char key[101];
int test;
while (scanf("%s%d", key, &test)) {
if (key[0] == '0' && test == 0)
break;

int hope = 0;
for (int c = 0; prime[c] < test; ++c) {
int temp = 0;
for (int d = 0; d < strlen(key); ++d) {
temp = (temp * 10) + (key[d] - '0');
temp %= prime[c];
}

if (temp == 0) {
hope = prime[c];
break;
}
}
if (hope)
else
printf("GOOD\n");
}

return 0;
}

• 本文已收录于以下专栏：

## Sicily 1231. The Embarrassed Cryptography【高精度取余】

• CharlieLincy
• 2014年12月04日 19:39
• 737

## 1231. The Embarrassed Cryptography

#include #include #include #define N 1000001 using namespace std; string num; int length; bool ...
• Er_mu
• 2014年11月20日 17:33
• 350

## sicily 1231 The Embarrassed Cryptography

• chocolate_22
• 2011年05月31日 23:33
• 1418

## 1231. The Embarrassed Cryptography(求两个素数积)

/*1231. The Embarrassed Cryptography(求两个素数积)*/ #include #include #include #include #include using na...
• xiehaoyun2012
• 2013年01月02日 20:05
• 359

## 1231. The Embarrassed Cryptography 可恶的边界

• calvin_zcx
• 2011年05月18日 21:54
• 498

## Sicily1231. The Embarrassed Cryptography

1231. The Embarrassed Cryptography Constraints Time Limit: 2 secs, Memory Limit: 32 MB De...
• u012925008
• 2015年03月18日 23:07
• 338

## 1231 The Embarrassed Cryptography

TAG  高精度以前的经验，转换成int数组时用比较大的进制程序会比较快。比如1000进制的话，123456789转换成{123,456,789}的一个数组。刚开始用了100000进制，没考虑到模除的...
• Dinosoft
• 2010年07月28日 01:13
• 1716

## sicily1231 The Embarrassed Cryptography

• guozhengchun
• 2014年11月23日 16:34
• 245

## Ural 1086. Cryptography 筛素数

1086. Cryptography Time limit: 2.0 second Memory limit: 64 MB While preparing this problem set t...
• jyysc2010
• 2013年07月30日 15:46
• 1042

## 使用cryptography进行AES的cbc模式加密

cryptography 是一个python加密库 cryptography is a package designed to expose cryptographic primitives an...
• Dawn_StatDust
• 2017年02月06日 15:18
• 1281

举报原因： 您举报文章：sicily 1231. The Embarrassed Cryptography 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)