大数取MOD。。。
The Embarrassed Cryptographer
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 11359 Accepted: 3026

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

Source

Nordic 2005

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int prim[80010],pn=0;
int p[1000010];
int big[100],cnt;/// wan jing zhi
char str[5000];

void getPRIM()
{
    for(int i=2;i<=1000000;i++)
        p=1;
    for(int i=2;i*i<=1000000;i++)
    {
        if(p)
        for(int j=2;j*i<=1000000;j++)
        {
            p[j*i]=0;
        }
    }
    for(int i=0;i<=1000000;i++)
    {
        if(p)
        {
            prim[pn++]=i;
        }
    }
}

void change2big(char str[500])
{
    int len=strlen(str),e=0,sum=0;cnt=0;
    for(int i=0;i<len;i++)
    {
         sum=sum*10+str-'0';
         e++;
         if(e>=4)
         {
             big[cnt++]=sum;
             sum=0;e=0;
         }
    }
    if(sum!=0)
    {
        big[cnt++]=sum;
    }
}

bool letsMOD(int mod)
{
    unsigned long long int ans=0;
    for(int i=0;i<cnt;i++)
    {
        ans=((ans*10000)+(big))%mod;
        //    printf("%d%%%d--->%d\n",big,mod,ans);
    }
    if((int)ans==0) return true;
    else return false;
}

int main()
{
    getPRIM();int L;
    while(scanf("%s%d",str,&L)!=EOF)
    {
        if(L==0&&strcmp(str,"0")==0) break;
        memset(big,0,sizeof(big));cnt=0;
        change2big(str);
        int pos=-1;
        for(int i=0;prim<L&&i<pn;i++)
        {
            //cout<<prim<<"....\n";
            if(letsMOD(prim))
            {
                pos=prim;
                break;
            }
        }
        if(pos!=-1)
            printf("BAD %d\n",pos);
        else
            printf("GOOD\n");
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 2635 The Embarrassed Cryptographer的更多相关文章

  1. [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   A ...

  2. POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15767   A ...

  3. poj 2635 The Embarrassed Cryptographer(数论)

    题目:http://poj.org/problem?id=2635 高精度求模  同余模定理. 题意: 给定一个大数K,K是两个大素数的乘积的值.再给定一个int内的数L 问这两个大素数中最小的一个是 ...

  4. POJ 2635 The Embarrassed Cryptographer 大数模

    题目: http://poj.org/problem?id=2635 利用同余模定理大数拆分取模,但是耗时,需要转化为高进制,这样位数少,循环少,这里转化为1000进制的,如果转化为10000进制,需 ...

  5. POJ 2635 The Embarrassed Cryptographer 高精度

    题目地址: http://poj.org/problem?id=2635 题意:给出一个n和L,一直n一定可以分解成两个素数相乘. 让你判断,如果这两个素数都大于等于L,则输出GOOD,否则输出最小的 ...

  6. POJ - 2635 The Embarrassed Cryptographer(千进制+同余模)

    http://poj.org/problem?id=2635 题意 给一个大数K,K一定为两个素数的乘积.现给出一个L,若K的两个因子有小于L的,就输出BAD,并输出较小的因子.否则输出GOOD 分析 ...

  7. POJ 2635 The Embarrassed Cryptographer(大数求余)

    题意:给出一个大数,这个大数由两个素数相乘得到,让我们判断是否其中一个素数比L要小,如果两个都小,输出较小的那个. 分析:大数求余的方法:针对题目中的样例,143 11,我们可以这样算,1 % 11 ...

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

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

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

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

随机推荐

  1. 向列布局动态添加F7

    function initBuildingEntryF7(sellId){ var comId = "buildingEntry"; var filter = "&quo ...

  2. PHP扩展——C扩展实现滚动记录日志

    前言 万事开头难,没错就是这样!! 在没有真正开发PHP扩展之前,一直觉得PHP扩展开发对我来说是一个很遥远的事情,虽然自己有些C\C++基础,但是看PHP源码的时候还是很吃力,现在看来主要还是没有下 ...

  3. jpa和hibernate注解

    http://www.objectdb.com/api/java/jpa/JoinColumns 用hibernate和jpa annotation 大概一年多了,今天闲来无事,对他们关联关系元数据写 ...

  4. [转]vim编辑器---批量注释与反注释

    转 在使用vim编写代码的时候,经常需要用到批量注释与反注释一段代码.下面简要介绍其操作. 方法一 块选择模式 插入注释: 用v进入virtual模式 用上下键选中需要注释的行数 按Control+v ...

  5. POJ1185炮兵阵地(状态压缩 + dp)

    题目链接 题意:给出一张n * m的地图,其中 有的地方能放大炮,有的地方不能,大炮与上下左右两个单位范围内会相互攻击,问最多能放几个大炮 能放大炮为1不能放大炮为0,把每一行看做一个状态,要除去同一 ...

  6. 处理字符串-String类和正则表达式

    ---基本元字符       . [] | () ---限定元字符      +至少匹配一个 *匹配0个或任意多个 ?匹配0个或1个(默认是贪心的)           当?在(*,+,?,{n},{ ...

  7. parted命令详解

    parted命令详解   用法:parted [选项]... [设备 [命令 [参数]...]...]   将带有“参数”的命令应用于“设备”.如果没有给出“命令”,则以交互模式运行.   帮助选项: ...

  8. 自然语言20_The corpora with NLTK

    QQ:231469242 欢迎喜欢nltk朋友交流 https://www.pythonprogramming.net/nltk-corpus-corpora-tutorial/?completed= ...

  9. Javascript权威指南——第二章词法结构,第三章类型、值和变量,第四章表达式和运算符,第五章语句

    第二章 词法结构 一.HTML并不区分大小写(尽管XHTML区分大小写),而javascript区分大小写:在HTML中,这些标签和属性名可以使用大写也可以使用小写,而在javascript中必须小写 ...

  10. 调用startActivityForResult,onActivityResult无响应的解决办法

    三种情况: 1.执行startActivityForResult,没等到被调用的 Activity 返回,onActivityResult() 就被执行了.找了很久,终于通过小道消息得知,这与 Act ...