The Embarrassed Cryptographer

Time Limit: 2000MS Memory Limit: 65536K

Total Submissions: 13041 Accepted: 3516

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

Source

Nordic 2005

判断所给的数是不是存在小于L的质因子;

思路:大数取模,

#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define PI cos(-1.0)
#define RR freopen("input.txt","r",stdin)
using namespace std;
typedef long long LL;
const int MAX = 1e6+100;
int Arr[100000];
int top;
bool vis[MAX];
char str[110];
int b[40];
int L;
bool flag;
int main()
{
memset(vis,false,sizeof(vis));
top=0;
for(LL i=2;i<MAX;i++)
{
if(!vis[i])
{
Arr[top++]=i;
for(LL j=i*i;j<MAX;j+=i)
{
vis[j]=true;
}
}
}
while(scanf("%s %d",str,&L))
{
if(str[0]=='0'&&L==0)
{
break;
}
flag=false;
int len=strlen(str);
int l=0;
for(int i=len-1;i>=0;i-=3)
{
int ans=0;
for(int j=2;j>=0;j--)
{
if(i-j<0)
{
continue;
}
ans=(ans*10+str[i-j]-'0');
}
b[l++]=ans;
}
int ans;
for(int i=0;Arr[i]<L;i++)
{
ans=0;
for(int j=l-1;j>=0;j--)
{
ans=(ans*1000+b[j])%Arr[i];
}
if(ans==0)
{
cout<<"BAD "<<Arr[i]<<endl;
flag=true;
break;
}
}
if(!flag)
{
cout<<"GOOD"<<endl;
}
}
return 0;
}

(POJ2635)The Embarrassed Cryptographer(大数取模)的更多相关文章

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

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

  2. The Embarrassed Cryptographer(高精度取模+同余模定理)

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11435   Accepted: 3040 Description The ...

  3. HDU-2303 The Embarrassed Cryptographer 高精度算法(大数取模)

    题目链接:https://cn.vjudge.net/problem/HDU-2303 题意 给一个大数K,和一个整数L,其中K是两个素数的乘积 问K的是否存在小于L的素数因子 思路 枚举素数,大数取 ...

  4. hdu2302(枚举,大数取模)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2303 题意:给出两个数k, l(4<= k <= 1e100, 2<=l<=1 ...

  5. 【大数取模】HDOJ-1134、CODEUP-1086

    1086: 大数取模   题目描述 现给你两个正整数A和B,请你计算A mod B.为了使问题简单,保证B小于100000. 输入 输入包含多组测试数据.每行输入包含两个正整数A和B.A的长度不超过1 ...

  6. HDU4704Sum 费马小定理+大数取模

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4704 题目大意: 看似复杂,其实就是求整数n的划分数,4=1+1+2和4=1+2+1是不同的.因而可 ...

  7. HDU--1212大数取模

    大数取模问题.题目传送门:HDU1212 #include <iostream> using namespace std; char a[1010]; int main() { int b ...

  8. ACM-ICPC 2018 焦作赛区网络预赛G Give Candies(隔板定理 + 小费马定理 + 大数取模,组合数求和)题解

    题意:给你n个东西,叫你把n分成任意段,这样的分法有几种(例如3:1 1 1,1 2,2 1,3 :所以3共有4种),n最多有1e5位,答案取模p = 1e9+7 思路:就是往n个东西中间插任意个板子 ...

  9. HPU 1471:又是斐波那契数列??(大数取模)

    1471: 又是斐波那契数列?? 时间限制: 1 Sec 内存限制: 128 MB 提交: 278 解决: 27 统计 题目描述 大家都知道斐波那契数列吧?斐波那契数列的定义是这样的: f0 = 0; ...

随机推荐

  1. c#操作Excel时,抛出异常:“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”

    我们开发环境下,使用excel导入数据到数据库中,编译的软件起初是x86 方式,起初并未发现什么问题,一切很正常: 程序该进的过程: 后来导入文件一次就要读取几百G的数据导入数据库中,使用编译的X86 ...

  2. MVC1

  3. tableview的cell点击和取消

    #pragma mark - 选择cell: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPa ...

  4. 转:python webdriver API 之鼠标事件

    前面例子中我们已经学习到可以用 click()来模拟鼠标的单击操作,而我们在实际的 web 产品测试中 发现,有关鼠标的操作,不单单只有单击,有时候还要和到右击,双击,拖动等操作,这些操作包含在Act ...

  5. Linux 配置双机SSH信任

    一.实现原理 使用一种被称为"公私钥"认证的方式来进行ssh登录."公私钥"认证方式简单的解释是: 首先在客户端上创建一对公私钥(公钥文件:~/.ssh/id_ ...

  6. Android Handler简单使用

    package com.example.myhandlertest3; import android.os.Bundle; import android.os.Handler; import andr ...

  7. 07---Net基础加强

    第六节复习 泛型和非泛型集合的区别 通常情况下,建议您使用泛型集合,因为这样可以获得类型安全的直接优点而不需要从基集合类型派生并实现类型特定的成员.此外,如果集合元素为值类型,泛型集合类型的性能通常优 ...

  8. mysql 导出过长的数字列时变科学计数法问题解决办法

    --mysql 导出数据时,  数字类型的列如果位数过长,变为科学技术发问题  concat('\t',a.IDCARD_NO)     例子: select   concat('\t',a.IDCA ...

  9. 11.Java反射机制 哦对了,前面的序号来自随笔关于编程之路的思索第一篇

    基本概念 在Java运行时环境中,对于任意一个类,能否知道这个类有哪些属性和方法?对于任意一个对象,能否调用它的任意一个方法? 答案是肯定的. 这种动态获取类的信息以及动态调用对象的方法的功能来自于J ...

  10. [OrangePi] Booting from USB drive

    You can also boot from USB drive partition. The file named cmdline.txt must exist on BOOT (fat) part ...