(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; ...
随机推荐
- CentOS 7 自动更新时间日期
# ntpdate time.nist.gov 或 # rdate -s time.nist.gov 下列服务器可用 time-nw.nist.gov
- winform 控件开发1——复合控件
哈哈是不是丑死了? 做了一个不停变色的按钮,可以通过勾选checkbox停下来,代码如下: 复合控件果然简单呀,我都能学会~ using System; using System.Collection ...
- 用Appium去操作移动设备上的chrome
最近在积极努力的学习Appium,今天成功运行了官网上的demo,在此做一个小小的总结: 前期准备工作: (1)在要运行的真机或模拟器上安装chrome. 注意:x86的虚拟机是不支持的,但是经过本人 ...
- paper 57 :颜色直方图的代码
clear clc close all Image = imread('29.jpg');[M,N,O] = size(Image);[h,s,v] = rgb2hsv(Image); H = h; ...
- rails控制台进入
数据库控制台: rails db .help查看可使用的命令 rails控制台 rails c 普通ruby控制台: irb
- oracle的函数
1:nvl函数 nvl函数将一个null值转换为一个实际的值,数据类型可以是日期,数字,字符,数据类型必须匹配,vl能够转换任何数据类型,但是转换的数据类型返回值必须是nvl(expr1,expr2) ...
- 使用sudo执行命令的时候提示找不到命令
事出有因, 源自使用源码编译 nginx , 在 /usr/local/sbin/ 目录下创建了nginx 启动的符号链接 , 执行 sudo nginx 的时候提示找不到命令, 但是使用普通用户身份 ...
- opencv常用数据结构之:IplImage
typedef struct_IplImage{ int nSize; //IplImage大小 int ID; //版本(=0) int nChannels; //大多 ...
- android 项目学习随笔十(自定义ProgressBar)
android:innerRadius 内部半径 android:thickness 厚度 gradient 渐变 android:useLevel="false" 取掉控件自带旋 ...
- button改变背景与文字颜色
1.定义/zhsh/res/color/txt_guide_selector.xml <?xml version="1.0" encoding="utf-8&quo ...