sicily 1231. The Embarrassed Cryptography

原创 2015年11月19日 13:00:58

1231. The Embarrassed Cryptography

Constraints

Time Limit: 2 secs, Memory Limit: 32 MB

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

题目分析

给定一个大整数和num,看大整数能否被比num小的素数整除
大整数除法,利用同余定理

#include <stdio.h>
#include <memory.h>
int prime[80000];
int count;

void init() {
  int visited[1000005];
  memset(visited, true, sizeof(visited));
  for (int c = 2; c < 1000005; ++c)
    if (visited[c])
      for (int d = c + c; d < 1000005; d += c)
        visited[d] = false;

  count = 0;
  for (int c = 2; c < 1000005; ++c)
    if (visited[c])
      prime[count++] = c;
}

int main()
{
  init();
  char key[101];
  int test;
  while (scanf("%s%d", key, &test)) {
    if (key[0] == '0' && test == 0)
      break;

    int hope = 0;
    for (int c = 0; prime[c] < test; ++c) {
      int temp = 0;
      for (int d = 0; d < strlen(key); ++d) {
        temp = (temp * 10) + (key[d] - '0');
        temp %= prime[c];
      }

      if (temp == 0) {
        hope = prime[c];
        break;
      }
    }
    if (hope)
      printf("BAD %d\n", hope);
    else
      printf("GOOD\n");
  }

  return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

Sicily 1231. The Embarrassed Cryptography【高精度取余】

题目链接在此 启示 1 用筛选法构造质数表; 启示 2 memset函数是以字节为单位操作数组的,对于char型数组,第二个参数怎样设置都行,因为每个char刚好就1个字节。但对于int型数组,就...
  • CharlieLincy
  • CharlieLincy
  • 2014年12月04日 19:39
  • 737

1231. The Embarrassed Cryptography

#include #include #include #define N 1000001 using namespace std; string num; int length; bool ...
  • Er_mu
  • Er_mu
  • 2014年11月20日 17:33
  • 350

sicily 1231 The Embarrassed Cryptography

这道题主要用到了一个筛法求素数,大数的模运算,以及暴力搜索的方法.....题意比较简单,关键要注意到大数的模运算问题!// source code of submission 784557, Zhon...
  • chocolate_22
  • chocolate_22
  • 2011年05月31日 23:33
  • 1418

1231. The Embarrassed Cryptography(求两个素数积)

/*1231. The Embarrassed Cryptography(求两个素数积)*/ #include #include #include #include #include using na...
  • xiehaoyun2012
  • xiehaoyun2012
  • 2013年01月02日 20:05
  • 359

1231. The Embarrassed Cryptography 可恶的边界

纪念第一次在实验室,用学校配的机器,用fedora,vim,交的第一题!再纪念一下明天考计算机网络期中,现在还没开始看呢... 线性搜索素数,然后简单的高精度取余数即可。注意的是边界情况!#inclu...
  • calvin_zcx
  • calvin_zcx
  • 2011年05月18日 21:54
  • 498

Sicily1231. The Embarrassed Cryptography

1231. The Embarrassed Cryptography Constraints Time Limit: 2 secs, Memory Limit: 32 MB De...
  • u012925008
  • u012925008
  • 2015年03月18日 23:07
  • 338

1231 The Embarrassed Cryptography

TAG  高精度以前的经验,转换成int数组时用比较大的进制程序会比较快。比如1000进制的话,123456789转换成{123,456,789}的一个数组。刚开始用了100000进制,没考虑到模除的...
  • Dinosoft
  • Dinosoft
  • 2010年07月28日 01:13
  • 1716

sicily1231 The Embarrassed Cryptography

题目链接:http://soj.me/1231 题目大意:给出一个(大)整数(是)
  • guozhengchun
  • guozhengchun
  • 2014年11月23日 16:34
  • 245

Ural 1086. Cryptography 筛素数

1086. Cryptography Time limit: 2.0 second Memory limit: 64 MB While preparing this problem set t...
  • jyysc2010
  • jyysc2010
  • 2013年07月30日 15:46
  • 1042

使用cryptography进行AES的cbc模式加密

cryptography 是一个python加密库 cryptography is a package designed to expose cryptographic primitives an...
  • Dawn_StatDust
  • Dawn_StatDust
  • 2017年02月06日 15:18
  • 1281
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:sicily 1231. The Embarrassed Cryptography
举报原因:
原因补充:

(最多只允许输入30个字)