Time Limit: 2sec    Memory Limit:32MB 
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
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAARABIDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAMFBwT/xAAlEAACAQQCAQMFAAAAAAAAAAABAgMABAURBiESIjFBMjZxdbP/xAAYAQACAwAAAAAAAAAAAAAAAAAAAwEEBf/EABsRAQEAAgMBAAAAAAAAAAAAAAEAAgMEEyFh/9oADAMBAAIRAxEAPwDQeRW+SyVnctBIkiiScOk87qm0ciP0aZWA8dkEDZA2fcGPCWPI+PXkUt3GIcQjkyQxTGdtMrAhUVQO5CraVd/UB1pa7cnHmbaW5hjxEktoZJJGulnjChWYsT4lvLoHvr3B1vommvuQYaSe/jGSxrW9yXEiCWIiTe9eWohvs/LH8n5ocDh9jlnsER+zt+9wDE9G0uKWO4hSaGRJIpFDI6MCrKewQR7ilVfFPs7B/r4P5rStB8ZJW9KUqIlKUoi//9k=" alt="" /> Copy sample input to clipboard 
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
分析:因为是 ^,所以不能直接用内置数据类型,只能用大整数
判断是否能整除的一个方法是判断模值是否为 ,因为大整数求模比除法更简单,所以直接求模
#include <iostream>
#include <string>
using namespace std; bool is_mod(string num,int n) // 判断是否能够被整除
{
int fac = ;
for(int i = ; i < num.size(); i++)
fac = (fac * + (num[i] - '')) % n;
if(fac == )
return true;
return false;
} int main(int argc, char const *argv[])
{
int prime[];
int primeNum = ;
for (int i = ; i != ; ++i) {
prime[i] = ;
}
for (int i = ; i != ; ++i) { // 筛选法求素数
if (prime[i] == ) {
prime[primeNum++] = i; // 将素数存到数组
for (int j = * i; j < ; j += i)
prime[j] = ;
}
} string num;
int lowerBound;
while (cin >> num) {
bool flag = true;
int factor = ;
cin >> lowerBound;
if (num == "" && lowerBound == )
break;
for (int i = ; i != primeNum; ++i) {
if (prime[i] < lowerBound) { // 找到最小的能被整除且在下界内部的素数
if (is_mod(num, prime[i])) {
flag = false;
factor = prime[i];
break;
}
}
}
if (flag)
cout << "GOOD" << endl;
else
cout << "BAD " << factor << endl;
}
return ;
}

sicily 1231. The Embarrassed Cryptography的更多相关文章

  1. .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数

    .Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...

  2. ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学

    ECC ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学,是目前已知的公钥体制中,对每比特所提供加密强度最高的一种体制.在软件注册保护方面起到很大的作用,一般的序列 ...

  3. "System.Security.Cryptography.CryptographicException: 拒绝访问" 问题的解决方法

    .net web程序使用rsa算法进行加解密时,程序报告“System.Security.Cryptography.CryptographicException: 拒绝访问”错.按网上搜的解决方法做了 ...

  4. sicily 中缀表达式转后缀表达式

    题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...

  5. sicily 1934. 移动小球

    Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...

  6. System.Security.Cryptography.CryptographicException: 指定了无效的提供程序类型

    这两天在调用银联在线的支付接口,把银联提供的demo代码copy过来放到自己网站上,生成通过了,但是运行的时候就报错了: 指定了无效的提供程序类型. 说明: 执行当前 Web 请求期间,出现未经处理的 ...

  7. POJ 2635 The Embarrassed Cryptographer

    大数取MOD... The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1 ...

  8. [POJ2109]Power of Cryptography

    [POJ2109]Power of Cryptography 试题描述 Current work in cryptography involves (among other things) large ...

  9. ACM: Gym 100935B Weird Cryptography - 简单的字符串处理

    Weird Cryptography Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. 开源入侵检测系统SELKS系统搭建

      一.系统环境配置 系统环境:centos7x64      ip地址:172.16.91.130 1.设置静态IP地址 [root@localhost backlion]#vi  /etc/sys ...

  2. 《Linux内核设计与实现》第7章读书笔记

    第七章 链接 一. 链接的概念 链接是将各种代码和数据部分收集起来并组合成为一个单一文件的过程.可以执行于编译.加载和运行时,由叫做链接器(可实现分离编译)的程序自动执行. 二.静态链接 为了创建静态 ...

  3. %1$s %1$d Android string (java & Android 格式化字符串)

    1$s // String%1$d // int //R.string.old:<string name="old">我今年%1$d岁了</string> ...

  4. 【arc102E】Stop. Otherwise...

    Portal --> arc102E Description 有\(N\)个位置,每个位置可以填一个\(1\sim K\)的数,要求对于每一个\(i\in [2,2K]\),求出任意两个位置的和 ...

  5. python之旅:文件处理

    一 文件操作及理论 1. 介绍 计算机系统分为:计算机硬件.操作系统.应用程序三部分我们用python或者其他程序,想要把数据永久的保存下来,就得写到硬盘里,但是应用程序是没有办法直接操作硬件的,这就 ...

  6. ES6学习(一)搭建环境

    作为一名后端小开发,业务工作需要将后台系统重构一番,许多同事都已经使用前后分离搭建项目,为了不拖后腿自己在家摸索ES6的新特性,真心不知道什么ES3,ES5,一上来就开始搞ES6,在此留下学习笔记,方 ...

  7. matlab绘制实用日历实例代码

    function TheStudy;%函数名 close all;%关闭所有床头 DD={'Sun','Mon','Tue','Wed','Thu','Fri','Sat'};%日历表头文字 figu ...

  8. bzoj千题计划160:bzoj2599: [IOI2011]Race

    http://www.lydsy.com/JudgeOnline/problem.php?id=2599 点分治 mi[i] 记录边权和为i时的最少边数 先更新答案,再更新mi数组,换根时清空mi # ...

  9. Tomcat开启Debug模式

    在bin/catalina.sh中添加如下行,将tomcat重启即可. 注:以下标红的7002需将其改成对象的tomcat端口即可! JAVA_OPTS=,server=y,suspend=n -Df ...

  10. 使用object_box遇到的崩溃 java.lang.UnsatisfiedLinkError:

    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ ...