POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 15767 | Accepted: 4337 |
Description

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 ...
随机推荐
- abs的个人博客 http://abs001.top/blog
abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 a ...
- go包的理解
结论: import时指定的字符串,是相对于$GOPATH的目录路径,告诉了go,要去加载这个目录下所有的包文件(不包括子目录中的文件) 一个目录中所有的源文件(不包括子目录)代表了单独的一个包,这些 ...
- linux常用指令学习记录
前言 本文主要为学习贴,用来记录一些 linux上的常用指令 以供参考. 文件内容查看 cat 从上往下阅读文件内容 cat [-AbEnTv] ${FILE_NAME) cat -n /etc/is ...
- 第7章 数据库访问与ORM 慕课网微信小程序开发学习笔记
第7章 数据库访问与ORM https://coding.imooc.com/learn/list/97.html 目录: 7-1 数据库操作三种方式之原生SQL 19:09 7-2 从一个错误了解E ...
- BootCDN 开源项目免费 CDN 加速服务,Jquery插件库
2017-11-17 19:38:32 免费好用的在线 css js 文件引用 BootCDN - Bootstrap 中文网开源项目免费 CDN 加速服务 Jquery插件库 .
- python3 包的发布
发布流程大概如下 1. 首先需要有一个python包,就是一个文件夹,但是此文件夹下面有__init__.py文件,里面内容是 现在要发布包TestMsg,这就是一个python包.在同级目录下新建s ...
- (新手)使用pandas操作EXCEL
import pandas as pdimport numpy as npfrom pandas import DataFrame,Series#path = r'C:\Users\tsl\Deskt ...
- C++学习网站——www.cplusplus.com
http://www.cplusplus.com/ 有各个函数.语法的实例代码,可以在线运行http://cpp.sh/不支持中文字符,不错.
- 定时任务之crond服务
计划任务分为一次性计划任务与长期性计划任务 一次性计划任务:今天11:25执行重启网卡操作,执行结束 即任务消失 一次性计划任务格式: 创建:"at 时间" #默认采用的是交互式 ...
- 第八届蓝桥杯C/C++ B组省赛----分巧克力
分巧克力 问题描述 儿童节那天有K位小朋友到小明家做客.小明拿出了珍藏的巧克力招待小朋友们. 小明一共有N块巧克力,其中第i块是Hi x Wi的方格组成的长方形. 为了公平起见,小明需要从这 N 块巧 ...