POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 15767 | Accepted: 4337 |
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
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
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
这个题最大的亮点就是利用千进制,100位只能这样。
很有意思的推论,利用同余定理,记住原理吧,这个规律挺神奇的,所以数学还挺好玩的
同余公式也有许多我们常见的定律,比如相等律,结合律,交换律,传递律….如下面的表示:
• 1)a≡a(modd)
• 2)a≡b(modd)→b≡a(mod d)
• 3)(a≡b(modd),b≡c(mod d))→a≡c(mod d)
• 如果a≡x(modd),b≡m(mod d),则
• 4)a+b≡x+m (mod d)
• 5)a-b≡x-m(mod d)
• 6)a*b≡x*m(mod d )
•
应用:
• (a+b)%c=(a%c+b%c)%c;
• (a*b)%c=(a%c*b%c)%c;
• 对于大数的求余,联想到进制转换时的方法,得到
• 举例如下,设大数 m=1234,模n
• 就等于((((1*10)%n+2%n)%n*10%n+3%n)%n*10%n+4%n)%n
大数求余的简单模板:
• #include<stdio.h>//大数求余,其中n(除数)不是大数
char a[1000];
int main()
int i,j,k,m,n;
{
while(scanf("%s%d",a,&n)!=EOF)
{
m=0;
for(i=0;a[i]!='\0';i++)
m=((m*10)%n+(a[i]-'0')%n)%n;
printf("%d\n",m);
}
return 0;
}
同时我是真的手残啊。。。小bug太多了。。真的是在写bug
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<iostream>
#include <cmath>
#include<string>
#define ll long long
#define dscan(a) scanf("%d",&a)
#define mem(a,b) memset(a,b,sizeof a)
using namespace std;
#define MAXL 1105
#define Endl endl
#define maxn 1000055
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>'') {if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<='') {x=*x+ch-'';ch=getchar();}
return x*f;
}
int isp[maxn],p[maxn],cnt;
void getp()
{ int cnt=;
for(int i=;i<=maxn;++i)
{
if(!isp[i]) p[cnt++]=i;
for(int j=;j<cnt&&p[j]*i<=maxn;++j){
isp[i*p[j]]=p[j];
if(i%p[j]==) break;
}
}
}
int num,nums,ks;
int main()
{
string s;
int n;
getp();
//for(int i=0;i<=10;++i) cout<<p[i]<<" ";
while(cin>>s>>n&&(s[]!=''&&n!=))
{
//cout<<s<<endl;
int len=s.length();
int i;
int flag=;
for(i=;p[i]<n;++i)
{
num=;
for(int j=;j<len;j+=)
{
nums=;
ks=;
for(int k=j;k<j+&&k<len;k++)
{
ks*=;
nums=nums*+s[k]-'';
}
num=num*ks+nums;
//cout<<"num="<<num<<endl;
num%=p[i];
//cout<<"num="<<num<<endl;
}
if(num==) {printf("BAD %d\n",p[i]);flag=;break;}
}
if(flag) printf("GOOD\n");
}
return ;
}
POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)的更多相关文章
- POJ - 2635 The Embarrassed Cryptographer(千进制+同余模)
http://poj.org/problem?id=2635 题意 给一个大数K,K一定为两个素数的乘积.现给出一个L,若K的两个因子有小于L的,就输出BAD,并输出较小的因子.否则输出GOOD 分析 ...
- poj 2635 The Embarrassed Cryptographer(数论)
题目:http://poj.org/problem?id=2635 高精度求模 同余模定理. 题意: 给定一个大数K,K是两个大素数的乘积的值.再给定一个int内的数L 问这两个大素数中最小的一个是 ...
- POJ 2635 The Embarrassed Cryptographer 大数模
题目: http://poj.org/problem?id=2635 利用同余模定理大数拆分取模,但是耗时,需要转化为高进制,这样位数少,循环少,这里转化为1000进制的,如果转化为10000进制,需 ...
- POJ 2635 The Embarrassed Cryptographer
大数取MOD... The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1 ...
- POJ 2635 The Embarrassed Cryptographer(大数求余)
题意:给出一个大数,这个大数由两个素数相乘得到,让我们判断是否其中一个素数比L要小,如果两个都小,输出较小的那个. 分析:大数求余的方法:针对题目中的样例,143 11,我们可以这样算,1 % 11 ...
- [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)
The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11978 A ...
- POJ 2635 The Embarrassed Cryptographer 高精度
题目地址: http://poj.org/problem?id=2635 题意:给出一个n和L,一直n一定可以分解成两个素数相乘. 让你判断,如果这两个素数都大于等于L,则输出GOOD,否则输出最小的 ...
- poj 2635 千进制
转自:http://www.cnblogs.com/kuangbin/archive/2012/04/01/2429463.html 大致题意: 给定一个大数K,K是两个大素数的乘积的值. 再给定一个 ...
- 【阔别许久的博】【我要开始攻数学和几何啦】【高精度取模+同余模定理,*】POJ 2365 The Embarrassed Cryptographer
题意:给出一大数K(4 <= K <= 10^100)与一整数L(2 <= L <= 106),K为两个素数的乘积(The cryptographic keys are cre ...
随机推荐
- mysql -u root -p 解释
使用此命令首先确保你的mysql运行环境已经搭建好 这是客户端连接mysql服务器的指令,比较全的写法是下面两种 第一个是全拼,第二个是第一个的缩写 mysql --host=localhost -- ...
- python 进度条 打印
- linux几种文件传输方式
本文记录linux系统中文件传输的多种方式,留作备忘.linux中文件传输的方式有ftp,scp,rsync,rz,sz等,但各个工具的功能又有所区别: FTP : FTP是文件服务器,可实现文件的上 ...
- Window_Bat_Scripts—检测特定网段未使用的IP地址
1.1 脚本名称 Check_IP_Not_Use.bat 1.2 脚本代码 @Echo off set /p input_number=请输入网络位(192.168.1.): IF EX ...
- 【Linux】linux 机器之间 zssh, rz, sz互相传输
服务器端安装lrzsz: sudo yum install lrzsz 本地客户端安装lrzsz: brew install lrzsz 本地客户端安装zssh: brew install zssh ...
- 微信小程序navigator的open-type跳转问题
navigator的open-type属性 可选值 'navigate'.'redirect'.'switchTab',对应于wx.navigateTo.wx.redirectTo.wx.switch ...
- Python知识点入门笔记——基本控制流程
复合赋值语句 在Python中,可以使用一次赋值符号,给多个变量同时赋值: 划重点:age_1,age_2 = age_2,age_1这种操作是Python独有的 i ...
- Watchmen CodeForces - 650A
Watchmen CodeForces - 650A Watchmen are in a danger and Doctor Manhattan together with his friend Da ...
- ZOJ Monthly, January 2018 训练部分解题报告
A是水题,此处略去题解 B - PreSuffix ZOJ - 3995 (fail树+LCA) 给定多个字符串,每次询问查询两个字符串的一个后缀,该后缀必须是所有字符串中某个字符串的前缀,问该后缀最 ...
- [转]webservice 采用SSL实现加密传输
本文转自:http://book.51cto.com/art/200906/129770.htm http://yeweiyun868.blog.163.com/blog/static/5637844 ...