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. Magento 2.1.X 插件(Plugin)的创建

    Magento 2的插件主要作用:在Magento 1中,为了自定义不同的类和方法,你可以重写一个类. 这是一个非常强大和灵活的定制平台的方式. 这也造成了麻烦,因为两个模块不可以重写同一个类, 重写 ...

  2. [js高手之路] es6系列教程 - 迭代器与生成器详解

    什么是迭代器? 迭代器是一种特殊对象,这种对象具有以下特点: 1,所有对象都有一个next方法 2,每次调用next方法,都会返回一个对象,该对象包含两个属性,一个是value, 表示下一个将要返回的 ...

  3. 如何实现跨 Docker 主机存储?- 每天5分钟玩转 Docker 容器技术(73)

    从业务数据的角度看,容器可以分为两类:无状态(stateless)容器和有状态(stateful)容器. 无状态是指容器在运行过程中不需要保存数据,每次访问的结果不依赖上一次访问,比如提供静态页面的 ...

  4. C#的"?"修饰符和"??"运算符

    一.  ?  可空类型修饰符 “?”用来修饰为空的值类型,在加上“?”修饰符后,值类型也可以为空了,如: public int? CommandTimeout { get; }: var prop = ...

  5. uva1267 Network

    https://vjudge.net/problem/UVA-1267 题意: 有一棵树,上面有一个放着水源的点s,给出一个数k,这个水源可以覆盖路径长度到s不超过k的叶子节点.现在需要把所有的叶子节 ...

  6. 剑指offer(纪念版) 面试题3:二维数组中的查找

    题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数.   第一种方法题目说不可行 ...

  7. SQL监测语句

    SELECT top 20 qs.creation_time,last_execution_time,total_physical_reads,total_logical_reads,total_lo ...

  8. git仓库管理笔录

    Git是目前世界上最先进的分布式版本控制系统(没有之一). 小明做了个个人博客,放到了Git 仓库里面.第二天换了台电脑,只需要 git clone  克隆一下git 远程仓库的代码到本地即可.然后他 ...

  9. zabbix灵活使用userparameters

    userparameters介绍 官网文献:https://www.zabbix.com/documentation/2.0/manual/config/items/userparameters 当我 ...

  10. 执行Sqlserver中waitfor delay延时操作或waitfor time定时操作

    private static string connectionString = RBAC.Dal.DataRootBase.ConnectionString; private SqlConnecti ...