The Embarrassed Cryptographer(高精度取模+同余模定理)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 11435 | Accepted: 3040 |
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
Output
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 题意:k是两个素数的乘积,但k是一个大数,若两个素数中最小的素数不小于l输出“GOOD",否则输出"BAD"和最小的素数;
思路:高精度取模:例如k是“1234567”,转化为千进制后,在kt数组里的形式为kt[1][234][567],在程序里的形式是kt[567][234][1],即整体逆序,局部有序;
同余模定理:如kt[567][234][1]对100取模,
1%100= 1;
(1*1000+234)%100 = 34;
(34*1000+567)%100 = 67;
67!=0,所以原来的k不能被100整除;
#include<stdio.h>
#include<string.h>
const int MAX = ;
int prime[MAX];
char k[];
int l;
int kt[];//将k转化成千进制数存到kt数组里; //素数筛;
void prime_table()
{
int pnum = ,i,j;
prime[pnum++] = ; for(i= ; i <= MAX; i+=)
{
bool flag = true;
for(j = ; prime[j]*prime[j] <= i; j++)
{
if(!(i%prime[j]))
{
flag = false;
break;
}
}
if(flag)
prime[pnum++] = i;
}
} //判断k能否被prime整除,同余模定理;
bool check(int kt[],int prime,int len)
{
int i;
int t = ;
for(i = len-; i >= ; i--)
t = (t*+kt[i])%prime;
if(t)
return false;
return true;
} int main()
{
int i,cnt;
prime_table();
while(~scanf("%s %d",k,&l))
{
if(k[] == '' && l == )
break;
memset(kt,,sizeof(kt)); int lenk = strlen(k); for(i = ; i < lenk; i++)
{
cnt = (lenk+-i)/-;
kt[cnt] = kt[cnt]*+(k[i]-'');
}//将k转化为千进制数,如“1234567”被转化为kt[567][234][1];
int lenkt = (lenk+)/;//kt数组的长度; bool flag = true;
int pnum = ;
while(prime[pnum] < l)
{
if(check(kt,prime[pnum],lenkt))
{
printf("BAD %d\n",prime[pnum]);
flag = false;
break;
}
pnum++;
}
if(flag)
printf("GOOD\n");
}
return ;
}
The Embarrassed Cryptographer(高精度取模+同余模定理)的更多相关文章
- 【阔别许久的博】【我要开始攻数学和几何啦】【高精度取模+同余模定理,*】POJ 2365 The Embarrassed Cryptographer
题意:给出一大数K(4 <= K <= 10^100)与一整数L(2 <= L <= 106),K为两个素数的乘积(The cryptographic keys are cre ...
- POJ2635——The Embarrassed Cryptographer(高精度取模+筛选取素数)
The Embarrassed Cryptographer DescriptionThe young and very promising cryptographer Odd Even has imp ...
- (POJ2635)The Embarrassed Cryptographer(大数取模)
The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13041 Accep ...
- HDU-2303 The Embarrassed Cryptographer 高精度算法(大数取模)
题目链接:https://cn.vjudge.net/problem/HDU-2303 题意 给一个大数K,和一个整数L,其中K是两个素数的乘积 问K的是否存在小于L的素数因子 思路 枚举素数,大数取 ...
- 组合数取模Lucas定理及快速幂取模
组合数取模就是求的值,根据,和的取值范围不同,采取的方法也不一样. 下面,我们来看常见的两种取值情况(m.n在64位整数型范围内) (1) , 此时较简单,在O(n2)可承受的情况下组合数的计算可以 ...
- hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)
DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...
- [转]组合数取模 Lucas定理
对于C(n, m) mod p.这里的n,m,p(p为素数)都很大的情况.就不能再用C(n, m) = C(n - 1,m) + C(n - 1, m - 1)的公式递推了. 这里用到Lusac定理 ...
- poj2635(千进制取模+同余模定理)
题目链接:https://www.cnblogs.com/kuangbin/archive/2012/04/01/2429463.html 题意:给出大数s (s<=10100) ,L (< ...
- 组合数取模&&Lucas定理题集
题集链接: https://cn.vjudge.net/contest/231988 解题之前请先了解组合数取模和Lucas定理 A : FZU-2020 输出组合数C(n, m) mod p (1 ...
随机推荐
- java.sql.SQLException: Invalid parameter object type. Expected 'java.util.Map' but found 'java.lang.String 转载
java.sql.SQLException: Invalid parameter object type. Expected 'java.util.Map' but found 'java.lang. ...
- eclipse 常见问题及解决
1. Target runtime Apache Tomcat v6.0 is not defined.错误解决方法 原文:http://blog.csdn.net/xw13106209/articl ...
- Eclipse配置使用web.xml
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/3792664.html ...
- (转)兼容主流浏览器的CSS透明代码
透明往往能产生不错的网页视觉效果下面是兼容主流浏览器的CSS透明代码.transparent_class { filter:alpha(opacity=50); -moz-opacity:0.5; - ...
- 17、SQL Server 备份和还原
SQL Server 备份 恢复模式 SQL Server 数据恢复模式分为三种:完整恢复模式.大容量日志恢复模式.简单恢复模式. 完整恢复模式 默认的恢复模式,它会完整记录下操作数据库的每一个步骤, ...
- JavaScript核心
JavaScript核心 arguments对象 Array对象 Boolean对象 Date对象 Error对象 Function对象 Global对象 Math对象 Number对象 Object ...
- EF 更新数据出现 System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: 异常
EF6更新 数据出现 System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: Store update, insert, or ...
- Singleton 模式
个人认为 Singleton 模式是设计模式中最为简单.最为常见.最容易实现,也是最应该熟悉和掌握的模式.且不说公司企业在招聘的时候为了考察员工对设计的了解和把握,考的最多的就是 Singleton ...
- Asp.net GridView 72般绝技
快速预览:GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠 ...
- openerp report image
webkit : 再mako 文件中插入以下代码, <% %>标签用于再mako中定义代码或者函数. 然后 ${ embed_image('图片类型', 图片字段 , 宽度,高度) } ...