zoukankan      html  css  js  c++  java
  • POJ 2635 The Embarrassed Cryptographer


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

    Description

    POJ 2635 The Embarrassed Cryptographer - qhn999 - 码代码的猿猿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 ",big,mod,ans);
        }
        if((int)ans==0return true;
        else return false;
    }

    int main()
    {
        getPRIM();int L;
        while(scanf("%s%d",str,&L)!=EOF)
        {
            if(L==0&&strcmp(str,"0")==0break;
            memset(big,0,sizeof(big));cnt=0;
            change2big(str);
            int pos=-1;
            for(int i=0;prim<L&&i<pn;i++)
            {
                //cout<<prim<<".... ";
                if(letsMOD(prim))
                {
                    pos=prim;
                    break;
                }
            }
            if(pos!=-1)
                printf("BAD %d ",pos);
            else
                printf("GOOD ");
        }
        return 0;
    }
    * This source code was highlighted by YcdoiT. ( style: Codeblocks )
  • 相关阅读:
    十进制转换成二进制列表
    openssl生成RSA格式的公私钥,并转为pkcs8格式
    yum安装报错:Failure when receiving data from the peer
    springboot配置swagger
    Impala配置HA-Nginx
    如何安装windows7
    MySQL数据实时增量同步到Kafka
    ElasticSearch-SQL 安装和使用
    部署nexus服务
    maven发布jar包到nexus
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350812.html
Copyright © 2011-2022 走看看