博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)
阅读量:5037 次
发布时间:2019-06-12

本文共 3185 字,大约阅读时间需要 10 分钟。

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 <= 10
100 and 2 <= L <= 10
6. 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 10143 20667 20667 302573 302573 400 0

Sample Output

GOODBAD 11GOODBAD 23GOODBAD 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

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #define ll long long 9 #define dscan(a) scanf("%d",&a)10 #define mem(a,b) memset(a,b,sizeof a)11 using namespace std;12 #define MAXL 110513 #define Endl endl14 #define maxn 100005515 inline ll read()16 {17 ll x=0,f=1;char ch=getchar();18 while(ch<'0'||ch>'9') { if(ch=='-') f=-1;ch=getchar();}19 while(ch>='0'&&ch<='9') {x=10*x+ch-'0';ch=getchar();}20 return x*f;21 }22 int isp[maxn],p[maxn],cnt;23 void getp()24 {25 26 int cnt=0;27 for(int i=2;i<=maxn;++i)28 {29 if(!isp[i]) p[cnt++]=i;30 for(int j=0;j
<=maxn;++j){31 isp[i*p[j]]=p[j];32 if(i%p[j]==0) break;33 }34 }35 }36 int num,nums,ks;37 int main()38 {39 string s;40 int n;41 getp();42 //for(int i=0;i<=10;++i) cout<
<<" ";43 while(cin>>s>>n&&(s[0]!='0'&&n!=0))44 {45 //cout<
<
View Code

 

转载于:https://www.cnblogs.com/TYH-TYH/p/9379514.html

你可能感兴趣的文章
聊天室(C++客户端+Pyhton服务器)_1.框架搭设
查看>>
UpdatePanel 内控件 更新“外的”控件【转】
查看>>
mybatis中&gt;=和&lt;=的实现方式
查看>>
Python面向对象03/继承
查看>>
java序列化和反序列化
查看>>
绝对定位
查看>>
flink源码编译(windows环境)
查看>>
dpkg 删除 百度网盘 程序
查看>>
服务器nginx安装
查看>>
std::nothrow
查看>>
rest-framework 分页器
查看>>
JQuery(一)安装&选择器 样式篇
查看>>
浏览器的DNS缓存查看和清除
查看>>
浏览器跨域问题
查看>>
HTML5 input控件 placeholder属性
查看>>
使用JAVA如何对图片进行格式检查以及安全检查处理
查看>>
html5实现移动端下拉刷新(原理和代码)
查看>>
iPhone开发中从一个视图跳到另一个视图有三种方法:
查看>>
pytho logging
查看>>
一个Java程序员应该掌握的10项技能
查看>>