Poj2635--the embarrassed cryptographer (number theory 1, large numbers modulus)

Source: Internet
Author: User
Tags modulus

The embarrassed cryptographer
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 12496 Accepted: 3330

Description

The young and very promising cryptographer ODD even have implemented the security module of a large system with thousands o F users, which is now-in The cryptographic keys are created from the product of both primes, and are believed to being secure because there is no known Method for factoring such a product effectively.
What ODD even does not think of, is, both factors in a key should is large, not just their product. It's now possible that some of the users of the system has weak keys. In a desperate attempt is fired, Odd even secretly goes through all the users keys, to check if they is strong ENO Ugh. He uses his very poweful Atari, and was especially careful when checking his boss ' key.

Input

The input consists of no more than test cases. Each test case was a line with the integers 4 <= K <= 10100 and 2 <= L <= 106. K is the key itself, a product of the 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 is 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 is separated by a line-break.

Sample Input

143 10143 20667 20667 302573 302573 400 0

Sample Output

Goodbad 11GOODBAD 23GOODBAD 31

Source

Nordic 2005

Title: Given two numbers k and l,k are multiplied by two primes, if the prime number is less than L, the output bad and that prime number, otherwise the output good.

First hit the prime table, which must have more than 1 million primes, the prime number in L and K to Die, where K is 10^100 used to large numbers to take the remainder, K into three-digit segment a[0] a[1], in the calculation

temp = A[0]%phi[i]

temp = (a[1]*1000+temp)%phi[i]

 

#include <cstdio> #include <cstring> #include <algorithm>using namespace std; #define LL __int64char    STR[200]; int n, a[100], num; int vis[2100000], phi[1100000], cnt; void init () {int i, J;    CNT = 0;    memset (vis,0,sizeof (VIS));        for (i = 2; I <= 2000000; i++) {if (!vis[i]) phi[cnt++] = i;            for (j = 0; J < CNT; J + +) {if (I*phi[j] >= 2000000) break;            VIS[I*PHI[J]] = 1;        if (i%phi[j] = = 0) break;    }}}int f (int k) {LL sum = 0, I, l;        for (i = num-1; I >= 0; i--) {sum = sum*1000 + a[i];    Sum%= k;    } if (sum = = 0) return 1; return 0;}    int main () {int I, J, L, Flag, s;    Init (); while (scanf ("%s%d", str, &n)! = EOF) {if (strlen (str) = = 1 && str[0] = = ' 0 ' && n = = 0)        break;        L = strlen (str);        memset (A,0,sizeof (a));        num = 0; FlAG = 0;            for (i = l-1; I >= 0; i--) {flag++;                if (flag = = 3) {A[num] = (str[i]-' 0 ') *100 + (str[i+1]-' 0 ') *10 + (str[i+2]-' 0 ');                num++;            Flag = 0;        }} if (flag = = 1) a[num++] = str[0]-' 0 ';        else if (flag = = 2) a[num++] = (str[0]-' 0 ') * + str[1]-' 0 ';            for (i = 0; i < cnt; i++) {if (Phi[i] >= n) break;        if (f (phi[i])) break;        } if (Phi[i] >= n | | i = CNT) printf ("good\n");    else printf ("Bad%d\n", Phi[i]); } return 0;}

Poj2635--the embarrassed cryptographer (number theory 1, large numbers modulus)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.