(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; ...
随机推荐
- SQL2008 R2 SP3中使用pivot实现行转列
同事遇到一个问题,怎么实现行转列,参考了别人的示例,我是这样解决的. 创建数据源: create table #temp ( objectid int, sitename ), cities ), p ...
- Python学习总结16:时间模块datetime & time & calendar (三)
calendar模块 常见函数及说明 1 calendar.calendar(year,w=2,l=1,c=6) 返回一个多行字符串格式的year年年历,3个月一行,间隔距离为c. 每日宽度间隔为 ...
- .NET: WPF Template
Data Template: 要做一个listBox,里面有车子的简单信息,点了里面的item后就会显示详细信息. car class: using System; using System.Coll ...
- .NET: C#: StopWatch
StopWatch class is used for calculate the timespan for that procedure. In Debug Mode it will be very ...
- 一个标准的ECharts代码
<!DOCTYPE html> <head> <meta charset="utf-8"> <title>ECharts</t ...
- Oracle角色
一 .3种标准角色 Qracle为了兼容以前的版本,提供了三种标准的角色(role):CONNECT.RESOURCE和DBA. 1. CONNECT Role(连接角色) 临时用户,特别是那些不需要 ...
- Android应用开发中的风格和主题(style,themes)
http://www.cnblogs.com/playing/archive/2011/04/01/2002469.html 越来越多互联网企业都在Android平台上部署其客户端,为了提升用户体验, ...
- Oracle中的rownum用法解析
注意:rownum从1开始: 1.rownum按照记录插入时的顺序给记录排序,所以有order by的子句时一定要注意啊! 2.使用时rownum,order by字段是否为主键有什么影响? 3 ...
- [OrangePi] Installation on internal EMMC
Install the image on SD Card as described above Boot your Orange PI board from SD Card Run: sudo ins ...
- pic计数
#include <pic.h> //用的是PICC编译器 __CONFIG (HS & PROTECT & PWRTEN & BOREN & WDTDIS ...