Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 11435   Accepted: 3040

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 题意: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(高精度取模+同余模定理)的更多相关文章

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

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

  2. POJ2635——The Embarrassed Cryptographer(高精度取模+筛选取素数)

    The Embarrassed Cryptographer DescriptionThe young and very promising cryptographer Odd Even has imp ...

  3. (POJ2635)The Embarrassed Cryptographer(大数取模)

    The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13041 Accep ...

  4. HDU-2303 The Embarrassed Cryptographer 高精度算法(大数取模)

    题目链接:https://cn.vjudge.net/problem/HDU-2303 题意 给一个大数K,和一个整数L,其中K是两个素数的乘积 问K的是否存在小于L的素数因子 思路 枚举素数,大数取 ...

  5. 组合数取模Lucas定理及快速幂取模

    组合数取模就是求的值,根据,和的取值范围不同,采取的方法也不一样. 下面,我们来看常见的两种取值情况(m.n在64位整数型范围内) (1)  , 此时较简单,在O(n2)可承受的情况下组合数的计算可以 ...

  6. hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)

    DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...

  7. [转]组合数取模 Lucas定理

    对于C(n, m) mod p.这里的n,m,p(p为素数)都很大的情况.就不能再用C(n, m) = C(n - 1,m) + C(n - 1, m - 1)的公式递推了. 这里用到Lusac定理 ...

  8. poj2635(千进制取模+同余模定理)

    题目链接:https://www.cnblogs.com/kuangbin/archive/2012/04/01/2429463.html 题意:给出大数s (s<=10100) ,L (< ...

  9. 组合数取模&&Lucas定理题集

    题集链接: https://cn.vjudge.net/contest/231988 解题之前请先了解组合数取模和Lucas定理 A : FZU-2020  输出组合数C(n, m) mod p (1 ...

随机推荐

  1. 利用switch语句进行多选一判断。

    <!doctype html> <meta http-equiv="content-type" content="text/html" cha ...

  2. ecshop了解01

    ecshop 是一个基于b2c的开源商城系统,从现在起来我也来学习一下,它是基于面向对象的,当然里面也有类. ecshop 的目录介绍 上面简单介绍一个ecshop的几个主要的文件,上面已经截图给大家 ...

  3. ssh框架简单搭建

    这里是个人对SSH框架搭建的一点心得,仅供新手,勿喷 首先,搞清楚分层, 视图层 --> 控制层  --> 业务层 --> DAO层--> 持久层 搭建的顺序是从后向前,搭建一 ...

  4. angularjs modal 嵌套modal的问题

    anguarjs中当遇到modal嵌套modal的时候,比如一个modal弹出啦一个modal1,关闭modal1后,modal本身的关闭功能失效,那么需要$modal来生命弹出的modal1并且关闭 ...

  5. ubuntu JDK

    第一步:下载jdk-7-linux-i586.tar.gz 第二步:解压安装 cd /usr/libsudo mkdir jvm cd {你的目录jdk压缩文件目录} sudo tar zxvf jd ...

  6. Angularjs总结(六) 上传附件

    所用插件:angular-file-upload 这个插件用到的几个指令:nv-file-select(点击选择).uploader(用于绑定控制器中新建的uploader对象) HTML: < ...

  7. Swift - 使用CoreLocation实现定位(经纬度、海拔、速度、距离等)

    CoreLocation是iOS中一个提供设备定位的框架.通过这个框架可以实现定位处理,从而获取位置数据,比如经度.纬度.海拔信息等.   1,定位精度的设置 定位服务管理类CLLocationMan ...

  8. Linux抓包工具tcpdump详解

    tcpdump是一个用于截取网络分组,并输出分组内容的工具,简单说就是数据包抓包工具.tcpdump凭借强大的功能和灵活的截取策略,使其成为Linux系统下用于网络分析和问题排查的首选工具. tcpd ...

  9. 关于this

    一:全局环境中的this指的是window对象 二:作为对象的方法调用 当函数作为对象的方法被调用时,this指向该对象 例子: 三:作为普通方法调用 当函数不作为对象的属性被调用,而是作为普通函数函 ...

  10. Access自动编号的初始值设置及重置编号 转

    方法如下: ALTER TABLE tableName ALTER COLUMN Id COUNTER (100, 5) 其中:tableName为要修改的表名,Id为自动编号列,100为初始值,5为 ...