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. objective-c 中的关联介绍

    objective-c 中的关联介绍 转载请注明CSDN博客上的出处: http://blog.csdn.net/daiyibo123/article/details/46471993 如何设置关联 ...

  2. 如何在单元测试中测试异步函数,block回调这种

    大概有四种方法: runloop 阻塞主进程等待结果 semphaore 阻塞主进程等待结果 使用XCTestExpectation 阻塞主线程等待(我用这个,xcode自带的,为啥不用) 使用第三方 ...

  3. PL/SQL 触发器简介

    与公司同事交流了一下,得知触发器很少用.性能是一方面,主要是如果用太多触发器,可能到时你都不知道会有什么操作自动发生. 有些操作可以在程序中控制.例如在插入某个表时,写个log表的记录.这可以用触发器 ...

  4. Extjs ——radiogroup子元素宽度调整

    配置项 类型 说明 allowBlank Boolean 设置是否必须选择至少一项,true表示可以不选,false表示不能为空至少选一项,默认为true blankText String 当allo ...

  5. Java实现ajax

    jsp端的代码,sucess:function(){} 里面就是返回的处理 function ChangeTime(){ alert("www"); var startYmd = ...

  6. 单例模式,多种实现方式JAVA

    转载请注明出处:http://cantellow.iteye.com/blog/838473 第一种(懒汉,线程不安全): public class Singleton { private stati ...

  7. linux创建用户

    创建用户   sudo adduser xxx 删除用户   sudo userdel xxx 删除用户和目录  sudo userdel -r xxx

  8. List<T>取交集、差集、并集

    1.  取交集 (A和B都有) List A : { 1 , 2 , 3 , 5 , 9 }List B : { 4 , 3 , 9 }var intersectedList = list1.Inte ...

  9. 『重构--改善既有代码的设计』读书笔记----Self Encapsulate Field

    如果你直接访问一个字段,你就会和这个字段直接的耦合关系变得笨拙.也就是说当这个字段权限更改,或者名称更改之后你的客户端代码都需要做相应的改变,此时你可以为这个字段建立设值和取值函数并且只以这些函数来访 ...

  10. centos安装nodejs和mongodb

    安装nodejs: Run as root on RHEL, CentOS or Fedora, for Node.js v4 LTS Argon: curl --silent --location ...