POJ2635-The Embarrassed Cryptographer-大整数素因子
计算一个大整数(10^100)中有没有一个小于L的素因子。这个大整数是两个素数的乘积。其实就是RSA加密。
做法是把大整数表示成千进位,用数组存储,然后一位一位地取模。
/*--------------------------------------------------------------------------------------*/
// Helica's header
// Second Editions
// 2015.11.7
//
#include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
/*--------------------------------------------------------------------------------------*/
using namespace std; int N,M,T,L;
char save[];
int num[]; const int MAXN = ;
int prime[MAXN]; void getPrime()
{
memset(prime,,sizeof prime);
for(int i=;i<=MAXN;i++)
{
if(!prime[i]) prime[++prime[]] = i;
for(int j=;j<=prime[]&&prime[j]<=MAXN/i;j++)
{
prime[prime[j]*i] = ;
if(i%prime[j] == ) break;
}
}
} bool mod(int p,int len)
{
int r = ;
for(int i=len-;i>=;i--)
r = (r* + num[i])%p; if(!r) return false;
else return true;
} int main()
{
getPrime(); while(scanf("%s%d",save,&L) && L)
{
int flag = ;
int len = strlen(save); memset(num,,sizeof num); for(int i=;i<len;i++)
{
int p = (len+-i)/-;
num[p] = num[p]*+(save[i]-'');
}
len = (len+)/; for(int i=;prime[i]<L;i++)
{
int p = prime[i];
//printf("p=%d\n",p);
if(!mod(p,len))
{
printf("BAD %d\n",p);
flag = false;
break;
}
}
if(flag) printf("GOOD\n");
}
}
POJ2635-The Embarrassed Cryptographer-大整数素因子的更多相关文章
- POJ2635——The Embarrassed Cryptographer(高精度取模+筛选取素数)
The Embarrassed Cryptographer DescriptionThe young and very promising cryptographer Odd Even has imp ...
- (POJ2635)The Embarrassed Cryptographer(大数取模)
The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13041 Accep ...
- HDU 2303 The Embarrassed Cryptographer
The Embarrassed Cryptographer 题意 给一个两个素数乘积(1e100)K, 给以个数L(1e6), 判断K的两个素数是不是都大于L 题解 对于这么大的范围,素数肯定是要打表 ...
- POJ 1811 Prime Test (Pollard rho 大整数分解)
题意:给出一个N,若N为素数,输出Prime.若为合数,输出最小的素因子.思路:Pollard rho大整数分解,模板题 #include <iostream> #include < ...
- HDU2303(数论)大整数求余+素数筛选
Sample Input 143 10 143 20 667 20 667 30 2573 30 2573 40 0 0 Sample Output GOOD BAD 11 GOOD BAD 23 ...
- Miller-Rabin 素性测试 与 Pollard Rho 大整数分解
\(\\\) Miller-Rabin 素性测试 考虑如何检验一个数字是否为素数. 经典的试除法复杂度 \(O(\sqrt N)\) 适用于询问 \(N\le 10^{16}\) 的时候. 如果我们要 ...
- Project Euler 29 Distinct powers( 大整数质因数分解做法 + 普通做法 )
题意: 考虑所有满足2 ≤ a ≤ 5和2 ≤ b ≤ 5的整数组合生成的幂ab: 22=4, 23=8, 24=16, 25=3232=9, 33=27, 34=81, 35=24342=16, 4 ...
- poj2389-Bull Math(大整数乘法)
一,题意: 大整数乘法模板题二,思路: 1,模拟乘法(注意"逢十进一") 2,倒序输出(注意首位0不输出) 三,步骤: 如:555 x 35 = 19425 5 5 5 5 5 ...
- AC日记——大整数的因子 openjudge 1.6 13
13:大整数的因子 总时间限制: 1000ms 内存限制: 65536kB 描述 已知正整数k满足2<=k<=9,现给出长度最大为30位的十进制非负整数c,求所有能整除c的k. 输入 ...
随机推荐
- LeetCode202:Happy Number 。C#版,在vs2010中通过,leetcode中Wrong Answer
static List<int> nums = new List<int>(); public static bool IsHappy(int n) { int newint ...
- 安装Debian后做的一些事情
1.source.list # aliyun deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib deb http: ...
- [06] 利用mybatis-generator自动生成代码
1.mybatis-generator 概述 MyBatis官方提供了逆向工程 mybatis-generator,可以针对数据库表自动生成MyBatis执行所需要的代码(如Mapper.java.M ...
- Linux shell ftp命令下载文件 根据文件日期
需求:ftp获取远程数据的文件,根据文件的创建时间点下载文件. 可以自行扩展根据文件的大小等其他需求. 知识点总结: 1.获取文件的时间: ls -lrt|awk '{print $6" & ...
- BZOJ1816 CQOI2010 扑克牌 贪心
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1816 题意:有$N$堆牌,第$i$堆牌有$c_i$张牌,还有$M$张$joker$,每 ...
- [Oracle]Oracle 各产品的 生命周期
http://www.oracle.com/us/support/library/lifetime-support-technology-069183.pdf
- python第二周。2019.4.13
1, 我绘制大蟒蛇就是..保存也对着呢,你要是打开文件的话,先闪个黑屏,再闪个白屏..自动退出,然后啥都没了. 我觉得是我代码编错了...再来一遍! 这次到可以,但是这个大蟒蛇好像没有回头... 刚才 ...
- Flutter - TabBar导航栏切换后,状态丢失
上一篇讲到了 Flutter - BottomNavigationBar底部导航栏切换后,状态丢失 里面提到了TabBar,这儿专门再写一下吧,具体怎么操作,来不让TabBar的状态丢失.毕竟大家99 ...
- ireportdesigner下载页面
iReport主页:http://community.jaspersoft.com/project/ireport-designer iReport下载地址:http://sourceforge.ne ...
- Redis日常操作命令小结
Redis缓存服务是运维工作中比较常见的一种维护工作,下面就redis日常操作命令在此做一简单小结,以备查用: 1)连接redis服务命令# redis-cli -h redis主机ip或主机域名 - ...