题目传送门:点击打开链接
The Embarrassed Cryptographer
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 14976 | Accepted: 4108 |
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.
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 <= 10
100 and 2 <= L <= 10
6. 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 其中k是由两个素数相乘得到的 如果这两个素数中较小的那个比L小的话就输出 BAD + 较小的那个素数 否则输出good
思路:首先K这个数是非常大的,不能用传统的方法去取模。。。。。
翻阅大神的博客后,知道了可以把K转换成千进制(这题中 百进制和万进制会错)数储存起来。然后再对L素数进行取模。这里要将素数提前打表处理好。
比如:2735可以转换为 2 735 存在另一个数组中。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define ll long long
#define M(a,b) memset(a,b,sizeof(a))
const int Max = 1e6+10;int prime[Max];
int check[Max];
void getprime()///素数打表部分
{int flag=0;for(int i=2; i<=Max; i++){if(!check[i]){prime[flag++]=i;}for(int j=i+i; j<=Max; j+=i){check[j]=1;}}}
bool MOD(int num[],int mod,int len)
{int lef=0;for(int i=len-1;i>=0;i--){lef=(lef*1000+num[i])%mod;///检测K能否整除这个素数}if(lef==0)///能整除{return 1;}else///不能整除{return 0;}
}
int main()
{char k[110];int l;int num[100];getprime();while(~scanf("%s %d",k,&l)){M(num,0);if(l==0&&strcmp(k,"0")==0){break;}int len=strlen(k);for(int i=0; i<len; i++){num[(len+2-i)/3-1]=(k[i]-'0')+num[(len+2-i)/3-1]*10;///将数字转化为1000进制}
// for(int i=0;i<=(len+2)/3-1;i++)
// {
// printf("%d\n",num[i]);
// }int xb=0;int flag=0;while(prime[xb]<l)///素数小于L{if(MOD(num,prime[xb],(len+2)/3))///且能被K整除{flag=1;printf("BAD %d\n",prime[xb]);break;}xb++;}if(flag==0){printf("GOOD\n");}}return 0;
}