POJ 2635 The Embarrassed Cryptographer 大数取模
来源:互联网 发布:上海网络推广铭心 编辑:程序博客网 时间:2024/06/06 01:10
题目传送门:点击打开链接
The Embarrassed Cryptographer
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 14976 Accepted: 4108
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.
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 10143 20667 20667 302573 302573 400 0
Sample Output
GOODBAD 11GOODBAD 23GOODBAD 31
Source
Nordic 2005
题意:给你两个数k和L 其中k是由两个素数相乘得到的 如果这两个素数中较小的那个比L小的话就输出 BAD + 较小的那个素数 否则输出good
思路:首先K这个数是非常大的,不能用传统的方法去取模。。。。。
翻阅大神的博客后,知道了可以把K转换成千进制(这题中 百进制和万进制会错)数储存起来。然后再对L素数进行取模。这里要将素数提前打表处理好。
比如:2735可以转换为 2 735 存在另一个数组中。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespace std;#define ll long long#define M(a,b) memset(a,b,sizeof(a))const int Max = 1e6+10;int prime[Max];int check[Max];void getprime()///素数打表部分{ int flag=0; for(int i=2; i<=Max; i++) { if(!check[i]) { prime[flag++]=i; } for(int j=i+i; j<=Max; j+=i) { check[j]=1; } }}bool MOD(int num[],int mod,int len){ int lef=0; for(int i=len-1;i>=0;i--) { lef=(lef*1000+num[i])%mod;///检测K能否整除这个素数 } if(lef==0)///能整除 { return 1; } else///不能整除 { return 0; }}int main(){ char k[110]; int l; int num[100]; getprime(); while(~scanf("%s %d",k,&l)) { M(num,0); if(l==0&&strcmp(k,"0")==0) { break; } int len=strlen(k); for(int i=0; i<len; i++) { num[(len+2-i)/3-1]=(k[i]-'0')+num[(len+2-i)/3-1]*10;///将数字转化为1000进制 }// for(int i=0;i<=(len+2)/3-1;i++)// {// printf("%d\n",num[i]);// } int xb=0; int flag=0; while(prime[xb]<l)///素数小于L { if(MOD(num,prime[xb],(len+2)/3))///且能被K整除 { flag=1; printf("BAD %d\n",prime[xb]); break; } xb++; } if(flag==0) { printf("GOOD\n"); } } return 0;}
阅读全文
0 0
- POJ 2635 The Embarrassed Cryptographer 大数取模
- POJ2635--The Embarrassed Cryptographer--大数取模
- (POJ2635)The Embarrassed Cryptographer(大数取模)
- The Embarrassed Cryptographer poj2635 (大数取模)
- POJ 2635 The Embarrassed Cryptographer 线性筛+高精度取模
- POJ 2635 The Embarrassed Cryptographer(千进制 高精度取模)
- POJ 2635 The Embarrassed Cryptographer 高精度取模 + 线性筛
- poj The Embarrassed Cryptographer(大数取模)(同余模定理)
- poj2635--The Embarrassed Cryptographer(数论篇1,大数取模)
- POJ 2635 The Embarrassed Cryptographer
- poj 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- poj-2635-The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- POJ 2635 The Embarrassed Cryptographer
- win7任务栏右下角图标空白解决办法
- HDU6059 Kanade's trio (Trie)
- Leetcode:621. Task Scheduler
- H5基础(3)-HTML5增强型表单标签
- SWT的button组件中,添加单击事件监听
- POJ 2635 The Embarrassed Cryptographer 大数取模
- 美图2017A卷第一题
- 【剑指offer】面试题15:链表中倒数第k个结点
- 23种设计模式汇总整理
- WebService访问数据
- Python正则表达式
- (lintcode)第16题 带重复元素的排列
- MySQL笔记【持续更新……】
- Java中==和equals的区别