The Embarrassed Cryptographer
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 15069   Accepted: 4132

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
BAD 11
GOOD
BAD 23
GOOD
BAD 31
/*
* @Author: lyucheng
* @Date: 2017-10-17 19:03:06
* @Last Modified by: lyucheng
* @Last Modified time: 2017-10-17 16:50:37
*/
#include <stdio.h>
#include <vector>
#include <string.h> #define MAXN 105
#define MAXM 1000005 using namespace std; char str[MAXN];
int k;
int p[MAXM];
bool prime[MAXM];
int tol;
int num[MAXM];
vector<int>v; void init(){
tol=;
for(int i=;i<MAXM;i++){
if(prime[i]==false)
p[tol++]=i;
for(int j=;j<tol&&i*p[j]<MAXM;j++){
prime[i*p[j]]=true;
if(i%p[j]==)
break;
}
}
} bool ok(int k){
int s=;
for(int i=(int)v.size()-;i>=;i--){
s*=;
s%=k;
s+=v[i];
s%=k;
}
if(s==)
return true;
else
return false;
} int main(){
// freopen("in.txt","r",stdin);
init();
while(scanf("%s%d",str,&k)!=EOF&&(str[]-''!=&&k!=)){
int n=strlen(str);
v.clear();
for(int i=n-;i>=;i-=){
int s=;
for(int j=max(,i-);j<=i;j++){
s*=;
s+=str[j]-'';
}
v.push_back(s);
}
// for(int i=0;i<(int)v.size();i++){
// cout<<v[i]<<" ";
// }cout<<endl;
bool flag=true;
for(int i=;p[i]<k;i++){
if(ok(p[i])==true){
printf("BAD %d\n",p[i]);
flag=false;
break;
}
}
if(flag==true)
puts("GOOD");
}
return ;
}

poj2635The Embarrassed Cryptographer(同余膜定理)的更多相关文章

  1. POJ2635The Embarrassed Cryptographer(大数取余+素数筛选+好题)

    题目链接 题意:K是由两个素数乘积,如果最小的素数小于L,输出BAD最小的素数,否则输出GOOD 分析 素数打表将 L 大点的素数打出来,一定要比L大,然后就开始枚举,只需K对 素数 取余 看看是否为 ...

  2. POJ2635-The Embarrassed Cryptographer 大数求余

    题目链接:http://poj.org/problem?id=2635 题目分析: http://blog.csdn.net/lyy289065406/article/details/6648530

  3. POJ 2635 The Embarrassed Cryptographer(大数求余)

    题意:给出一个大数,这个大数由两个素数相乘得到,让我们判断是否其中一个素数比L要小,如果两个都小,输出较小的那个. 分析:大数求余的方法:针对题目中的样例,143 11,我们可以这样算,1 % 11 ...

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

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

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

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

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

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

  7. POJ 2635 The Embarrassed Cryptographer

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

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

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

  9. 推荐系列:最小与最大[DP+余式定理]

    最小与最大 [问题描述] 做过了乘积最大这道题,相信这道题也难不倒你. 已知一个数串,可以在适当的位置加入乘号(设加了k个,当然也可不加,即分成k+1个部分),设这k+1个部分的乘积(如果k=0,则乘 ...

随机推荐

  1. PuTsangTo-单撸游戏开发03 碰撞与跳跃瑕疵版

    继续上一部分,游戏的定位是横版平台动作类游戏,所以得有跳跃动作,首先想到的就是物理引擎,不过在2D游戏里,仅为了角色的跳跃而引入物理引擎,目前想来有些不至于,仅使用cocos默认带有的碰撞系统也足够了 ...

  2. Spark任务流程笔记

    Spark学习笔记总结 02. Spark任务流程 1. RDD的依赖关系 RDD和它依赖的父RDD(s)的关系有两种不同的类型,即窄依赖(narrow dependency)和宽依赖(wide de ...

  3. 中位数的和_KEY

    中位数的和 (number.pas/c/cpp) [题目描述] flower 有 N-1 个朋友,他们要一起玩一个游戏:首先确定三个非负整数 a,b,c,然后每个人依次在纸上写一个数,设第 i 个人写 ...

  4. 国外支付PayPal

    PayPal官网https://www.paypal.com/ PayPal沙箱https://www.sandbox.paypal.com/signin?country.x=US&local ...

  5. MySQL所学所思所想

    MySQL更改线上配置方案思想:原则上,需要备机.备份工作准备到位,有参数调优配置方案.有配置回退方案.有应急切换备机方案.以上方案评审无问题,然后可以和客户约定实施的时间.服务中断时间,先向客户侧申 ...

  6. dubbo负载均衡策略及对应源码分析

    在集群负载均衡时,Dubbo 提供了多种均衡策略,缺省为 random 随机调用.我们还可以扩展自己的负责均衡策略,前提是你已经从一个小白变成了大牛,嘻嘻 1.Random LoadBalance 1 ...

  7. JavaScript 版数据结构与算法(四)集合

    今天,我们要讲的是数据结构与算法中的集合. 集合简介 什么是集合?与栈.队列.链表这些顺序数据结构不同,集合是一种无序且唯一的数据结构.集合有什么用?在 Python 中,我经常使用集合来给数组去重: ...

  8. Java面向对象 集合(中)

     Java面向对象 集合(中) 知识概要:                   (1)泛型的体系概念 (2)泛型的特点 (3)自定义泛型类 泛型的体系概念           泛型:JDK1.5版 ...

  9. C#综合揭秘——细说多线程(二)

    /* 异步写入 FileStream中包含BeginWrite.EndWrite 方法可以启动I/O线程进行异步写入. public override IAsyncResult BeginWrite ...

  10. MVC.NET 发布后,部署到iis ,网站中的Bootstrap的字体图标不能正常显示

    时隔多日没有在博客中记录自己遇到的问题及解决方案了 ,今天给大家分享一个可能会遇到的一个鸡肋bug ! 如果你的项目是MVC并且在项目中引用了 Boostrap 框架,你在编辑发布后部署到iis的时候 ...