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 <= 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 题意:求给出的一个数,求k中是否有比L小的的因子,其中K是大数 思路:因为我们L范围只有1e6,所以我们找寻因子可以直接遍历1-(L-1),然后我们进行大数取余操作,直接看余数是否为0即可
但是这样的时间复杂度就超时了,字符串长度是100 * L范围1e6 * 20组数据 = 2*1e9 (超时)
这个时候我们就要进行优化20组数据我们无法优化,只能从大数取余和找因子这里入 1,找因子
我们可以只找素因子,如果素因子都不可以说明其他因子也行不通,所以我们可以进行素数筛法打表 2.大数取余
因为我们在进行找因子的时候我们每次都要进行大数取余,重复这个操作,我们就可以进行大数转换千进制,就可以在进行大数取余操作的时候大大缩减时间复杂度
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define MAX 1000100
using namespace std;
int n;
int prime[MAX+];
char str[];
void primetable()//素数打表
{
int ps=;
prime[ps++]=;
for(int i=;i<=MAX;i+=)
{
int flag=;
for(int j=;prime[j]*prime[j]<=i;j++)
if(!(i%prime[j]))
{
flag=;
break;
}
if(flag)
prime[ps++]=i;
}
}
int main()
{
primetable();
while(scanf("%s%d",str,&n)!=EOF)
{
if(str[]==''&&n==) break;
int len=strlen(str);
int ans=;
int a[];
for(int i=len-;i>=;)//转换成千进制
{
if(i<){
if(i==)
a[ans++]=str[i]-'';
else a[ans++]=str[i]-''+(str[i-]-'')*;
i=-;
}
else{
a[ans++]=str[i]-''+(str[i-]-'')*+(str[i-]-'')*;
i-=;
}
}
int flag=;
for(int i=;prime[i]<n;i++)//遍历素因子
{
long long sum=;
for(int j=ans-;j>=;j--)
{
sum=(sum*+a[j])%prime[i];
}
if(sum==)
{
printf("BAD %d\n",prime[i]);
flag=;
break;
}
}
if(flag==)
{
printf("GOOD\n");
}
}
}
												

POJ - 2635 E - The Embarrassed Cryptographer的更多相关文章

  1. POJ 2635 The Embarrassed Cryptographer

    大数取MOD... The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1 ...

  2. [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   A ...

  3. POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15767   A ...

  4. (POJ2635)The Embarrassed Cryptographer(大数取模)

    The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13041 Accep ...

  5. POJ2635——The Embarrassed Cryptographer(高精度取模+筛选取素数)

    The Embarrassed Cryptographer DescriptionThe young and very promising cryptographer Odd Even has imp ...

  6. poj2635The Embarrassed Cryptographer(同余膜定理)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15069   A ...

  7. HDU 2303 The Embarrassed Cryptographer

    The Embarrassed Cryptographer 题意 给一个两个素数乘积(1e100)K, 给以个数L(1e6), 判断K的两个素数是不是都大于L 题解 对于这么大的范围,素数肯定是要打表 ...

  8. poj 2635 The Embarrassed Cryptographer(数论)

    题目:http://poj.org/problem?id=2635 高精度求模  同余模定理. 题意: 给定一个大数K,K是两个大素数的乘积的值.再给定一个int内的数L 问这两个大素数中最小的一个是 ...

  9. POJ 2635 The Embarrassed Cryptographer 大数模

    题目: http://poj.org/problem?id=2635 利用同余模定理大数拆分取模,但是耗时,需要转化为高进制,这样位数少,循环少,这里转化为1000进制的,如果转化为10000进制,需 ...

随机推荐

  1. 看到篇博文,用python pandas改写了下

    看到篇博文,https://blog.csdn.net/young2415/article/details/82795688 需求是需要统计部门礼品数量,自己简单绘制了个表格,如下: 大意是,每个部门 ...

  2. LeetCode--400--第N个数字

    问题描述: 在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 n 个数字. 注意: n 是正数且在32为整形范围内 ( n < 231). ...

  3. win10+cpu+tensorflow+pycharm

    1.安装64位的python3.5 选择windowsx86-64 executable installer安装 2.安装tensorflow cmd->进入到安装python的Scripts文 ...

  4. JavaScript 入门笔记

    JavaScript   1.JS和DOM的关系 浏览器有渲染html代码的功能,把html源码在内存里形成一个DOM对象,就是文档对象 浏览器内部有一个JS的解释器/执行/引擎,如chrome用v8 ...

  5. appium自动化测试(四)

    一. 获取webview的html页面 方法一: 1. 获取webview中对应的html页面 谷歌浏览器中输入地址:chrome://inspect(第一次使用要FQ) 前提:手机开启USB调试模式 ...

  6. node模块之net模块——socket

    当我们去面试的时候,常常会遇到这样一个问题:当用户在浏览器地址栏输入一段url发出资源请求后,到服务端返回数据呈现给用户的这个过程都发生了什么? 我们把进行通信的这两个端(这里指的是,浏览器和资源获取 ...

  7. MySQL 处理海量数据时一些优化查询速度方法

    1.应尽量避免在where子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在where及order by设计的列上建立 ...

  8. C++的面试题

    1.什么是类? 类是具有相同属性和相同的方法的对象的集合,它是一种既包含数据又包含函数的抽象数据类型. 对象是类进行实体化后的产物,是一个实体. 在C++中也是先声明一个类类型,用类去定义若干个同类型 ...

  9. 从零搭建和配置OSX开发环境

    对于每一名开发者来说,更换系统或者更换电脑的时候,都免不了花上不短的时间去折腾开 发环境的问题.我本人也是三番两次,深知这个过程的繁琐.所有,根据我自己以往的经验, 以及参考一下他人的意见,整理一下关 ...

  10. 基本数据类型int,bool,str

    .基本数据类型(int,bool,str) 基本数据数据类型: int 整数 str 字符串. 一般不存放大量的数据 bool 布尔值. 用来判断. True, False list 列表.用来存放大 ...