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

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
这个题最大的亮点就是利用千进制,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 (千进制,素数筛,同余定理)的更多相关文章

  1. POJ - 2635 The Embarrassed Cryptographer(千进制+同余模)

    http://poj.org/problem?id=2635 题意 给一个大数K,K一定为两个素数的乘积.现给出一个L,若K的两个因子有小于L的,就输出BAD,并输出较小的因子.否则输出GOOD 分析 ...

  2. poj 2635 The Embarrassed Cryptographer(数论)

    题目:http://poj.org/problem?id=2635 高精度求模  同余模定理. 题意: 给定一个大数K,K是两个大素数的乘积的值.再给定一个int内的数L 问这两个大素数中最小的一个是 ...

  3. POJ 2635 The Embarrassed Cryptographer 大数模

    题目: http://poj.org/problem?id=2635 利用同余模定理大数拆分取模,但是耗时,需要转化为高进制,这样位数少,循环少,这里转化为1000进制的,如果转化为10000进制,需 ...

  4. POJ 2635 The Embarrassed Cryptographer

    大数取MOD... The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1 ...

  5. POJ 2635 The Embarrassed Cryptographer(大数求余)

    题意:给出一个大数,这个大数由两个素数相乘得到,让我们判断是否其中一个素数比L要小,如果两个都小,输出较小的那个. 分析:大数求余的方法:针对题目中的样例,143 11,我们可以这样算,1 % 11 ...

  6. [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   A ...

  7. POJ 2635 The Embarrassed Cryptographer 高精度

    题目地址: http://poj.org/problem?id=2635 题意:给出一个n和L,一直n一定可以分解成两个素数相乘. 让你判断,如果这两个素数都大于等于L,则输出GOOD,否则输出最小的 ...

  8. poj 2635 千进制

    转自:http://www.cnblogs.com/kuangbin/archive/2012/04/01/2429463.html 大致题意: 给定一个大数K,K是两个大素数的乘积的值. 再给定一个 ...

  9. 【阔别许久的博】【我要开始攻数学和几何啦】【高精度取模+同余模定理,*】POJ 2365 The Embarrassed Cryptographer

    题意:给出一大数K(4 <= K <= 10^100)与一整数L(2 <= L <= 106),K为两个素数的乘积(The cryptographic keys are cre ...

随机推荐

  1. Mycat高可用解决方案三(读写分离)

    Mycat高可用解决方案三(读写分离) 一.系统部署规划 名称 IP 主机名称 配置 192.168.199.112 mycat01 2核/2G Mysql主节点 192.168.199.110 my ...

  2. python简单实用gunicorn部署

    linux 安装 pyuthon 安装   pip install gunicorn manage.py 文件 from app import create_app app = create_app( ...

  3. MySQL解决中文编码问题

    转载组员博客 地址:MySQL解决中文编码问题

  4. crontab -e 和/etc/crontab的区别

    /etc/crontab文件和crontab -e命令区别/etc/crontab文件和crontab -e命令区别 1.格式不同 前者 # For details see man 4 crontab ...

  5. thinkphp 3.2.3 - Think.class.php 解析

    class Think { public static function start() { // 注册AUTOLOAD方法 spl_autoload_register('Think\Think::a ...

  6. javascript sprintf方法

    转载自: http://demon.tw/programming/javascript-sprintf.html function str_repeat(i, m) { for (var o = [] ...

  7. linux的发展过程

    1. 操作系统 人与计算机硬件直接的中介 2. Linux系统组成 3. Linux的发展过程 蛋-人-人-人 unix于诞生贝尔实验室 人-谭教授 谭宁邦 minix mini unix. 主要用于 ...

  8. proguaid 混淆代码

    注意:这里有一个坑.就是-ignorewarnings 他老是混淆不了,告诉你不行.其实加上这句话,就可以了. 下面贴一下代码: -injars c:/ceb_lib.jar -outjars c:/ ...

  9. laravel5.2总结--服务容器(依赖注入,控制反转)

    1.依赖 我们定义两个类:class Supperman 和 class Power,现在我们要使用Supperman ,而Supperman 依赖了Power class Supperman { p ...

  10. java web知识点

    java web知识点 1.Java知识点 基本数据类型,面向对象,异常,IO,NIO,集合,多线程,JVM,高级特性. 2.web知识点 JSP,Serlvet,JDBC,Http 掌握Cookie ...