sicily 1231. The Embarrassed Cryptography
|
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.
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 Sample Output
GOOD |
分析:因为是 ^,所以不能直接用内置数据类型,只能用大整数
判断是否能整除的一个方法是判断模值是否为 ,因为大整数求模比除法更简单,所以直接求模
#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的更多相关文章
- .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数
.Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...
- ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学
ECC ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学,是目前已知的公钥体制中,对每比特所提供加密强度最高的一种体制.在软件注册保护方面起到很大的作用,一般的序列 ...
- "System.Security.Cryptography.CryptographicException: 拒绝访问" 问题的解决方法
.net web程序使用rsa算法进行加解密时,程序报告“System.Security.Cryptography.CryptographicException: 拒绝访问”错.按网上搜的解决方法做了 ...
- sicily 中缀表达式转后缀表达式
题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...
- sicily 1934. 移动小球
Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...
- System.Security.Cryptography.CryptographicException: 指定了无效的提供程序类型
这两天在调用银联在线的支付接口,把银联提供的demo代码copy过来放到自己网站上,生成通过了,但是运行的时候就报错了: 指定了无效的提供程序类型. 说明: 执行当前 Web 请求期间,出现未经处理的 ...
- POJ 2635 The Embarrassed Cryptographer
大数取MOD... The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1 ...
- [POJ2109]Power of Cryptography
[POJ2109]Power of Cryptography 试题描述 Current work in cryptography involves (among other things) large ...
- ACM: Gym 100935B Weird Cryptography - 简单的字符串处理
Weird Cryptography Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- 【省选水题集Day1】一起来AK水题吧! 题目(更新到B)
题解:http://www.cnblogs.com/ljc20020730/p/6937954.html 水题A: [AHOI2001]质数和分解 题目网址: https://www.luogu.or ...
- Mininet 系列实验(二)
实验内容 分别通过命令行创建.Python脚本编写以及交互式界面创建来熟悉Mininet的基本功能. 参考 Mininet命令延伸实验扩展 实验环境 虚拟机:Oracle VM VirtualBox ...
- 【ARC074e】RGB sequence
Description 一排\(n\)个格子,每个格子可以涂三种颜色的一种.现在给出\(m\)个形如"\([l,r]\)中必须恰好有\(x\)种颜色"的限制(\(1 \le l ...
- debian修改默认编辑器
刚才在一台机器上打开 crontab -e,跳出来的编辑器是nano,太难使... 在debian下是使用 update-alternatives 命令修改默认编辑器. 先查看一下使用帮助 # upd ...
- c++设计模式之抽象工厂模式
抽象工厂思想理解:可能有若干个你想生产的产品类,建立个工厂负责分别生产各类产品,由外部客户来选取想要那种产品类,此程序中没有delete,如想delete可在工厂类中的析构函数中实现(若有错请纠正)# ...
- C++命名规则 (转载仅作参考)
如果想要有效的管理一个稍微复杂一点的体系,针对其中事物的一套统一.带层次结构.清晰明了的命名准则就是必不可少而且非常好用的工具. 活跃在生物学.化学.军队.监狱.黑社会.恐怖组织等各个领域内的大量有识 ...
- Docker Secrets
一.简介 在微服务架构应用中,众多组件在集群中动态地创建.伸缩.更新.在如此动态和大规模的分布式系统上,管理和分发密码.证书等敏感信息将会是非常具有挑战性的工作.对于容器应用,传统的秘密分发方式,如将 ...
- P4779 【模板】单源最短路径(标准版)
P4779 [模板]单源最短路径(标准版) 求单源最短路, 输出距离 Solution \(nlogn\) 堆优化 \(Djs\) Code #include<iostream> #inc ...
- NP难问题
转自https://blog.csdn.net/u014295667/article/details/47090639 1.首先涉及到的基本概念有: (1)确定性算法(Determinism): 设A ...
- 51nod1019 逆序数
1019 逆序数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为 ...
