(POJ2635)The Embarrassed Cryptographer(大数取模)
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(大数取模)的更多相关文章
- POJ2635——The Embarrassed Cryptographer(高精度取模+筛选取素数)
The Embarrassed Cryptographer DescriptionThe young and very promising cryptographer Odd Even has imp ...
- The Embarrassed Cryptographer(高精度取模+同余模定理)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11435 Accepted: 3040 Description The ...
- HDU-2303 The Embarrassed Cryptographer 高精度算法(大数取模)
题目链接:https://cn.vjudge.net/problem/HDU-2303 题意 给一个大数K,和一个整数L,其中K是两个素数的乘积 问K的是否存在小于L的素数因子 思路 枚举素数,大数取 ...
- hdu2302(枚举,大数取模)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2303 题意:给出两个数k, l(4<= k <= 1e100, 2<=l<=1 ...
- 【大数取模】HDOJ-1134、CODEUP-1086
1086: 大数取模 题目描述 现给你两个正整数A和B,请你计算A mod B.为了使问题简单,保证B小于100000. 输入 输入包含多组测试数据.每行输入包含两个正整数A和B.A的长度不超过1 ...
- HDU4704Sum 费马小定理+大数取模
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4704 题目大意: 看似复杂,其实就是求整数n的划分数,4=1+1+2和4=1+2+1是不同的.因而可 ...
- HDU--1212大数取模
大数取模问题.题目传送门:HDU1212 #include <iostream> using namespace std; char a[1010]; int main() { int b ...
- 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个东西中间插任意个板子 ...
- HPU 1471:又是斐波那契数列??(大数取模)
1471: 又是斐波那契数列?? 时间限制: 1 Sec 内存限制: 128 MB 提交: 278 解决: 27 统计 题目描述 大家都知道斐波那契数列吧?斐波那契数列的定义是这样的: f0 = 0; ...
随机推荐
- __int64和long long输入输出
__int64 num; scanf("%I64d", &num); printf("%I64d\n", num); long long num; sc ...
- JSP out乱码
在form method="post" 写post 在接受页面jsp代码前面加request.setCharacterEncoding("UTF-8");
- 转:python webdriver API 之 获取对象的属性
获取测试对象的属性能够帮我们更好的进行对象的定位.比如页面上有很多标签为 input 元素,而我们需要定位其中 1 个有具有 data-node 属性不一样的元素.由于 webdriver 是不支持直 ...
- 点的双联通+二分图的判定(poj2942)
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 10804 Acce ...
- 算法提高 c++_ch02_01
http://lx.lanqiao.org/problem.page?gpid=T237 算法提高 c++_ch02_01 时间限制:1.0s 内存限制:512.0MB 编写一个程 ...
- android 内存不足的问题
FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring project ' ...
- Java实现数组按数值大小排序
package shb.java.test; /** * 比较数组中元素的大小,按从大到小顺序排列. * @Package:shb.java.test * @Description: * @autho ...
- js break continue
for 循环从 1 到 10 迭代变量 i.在循环主体中,if 语句将(使用取模运算符)检查 i 的值是否能被 5 整除.如果能被 5 整除,将执行 break 语句.alert 显示 "4 ...
- jQuery操作json数据
json是一种轻量级数据交换格式,简单的json格式为[{"key1":"value1"},{"key2":"value2&quo ...
- 要心中有“数”——C语言初学者代码中的常见错误与瑕疵(8)
在 C语言初学者代码中的常见错误与瑕疵(7) 中,我给出的重构代码中存在BUG.这个BUG是在飞鸟_Asuka网友指出“是不是时间复杂度比较大”,并说他“第一眼看到我就想把它当成一个数学问题来做”之后 ...