HDU 1211 EXGCD
EXGCD的模板水题
RSA算法
给你两个大素数p,q
定义n=pq,F(n)=(p-1)(q-1)
找一个数e 使得(e⊥F(n))
实际题目会给你e,p,q
计算d,$de \mod F(n) = 1$
然后解密的值为$c_{i}^d \mod n$,转换成char输出 用EXGCD求出d就好了
/** @Date : 2017-09-07 22:17:00
* @FileName: HDU 1211 EXGCD.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; LL exgcd(LL a, LL b, LL &x, LL &y)
{
LL d = a;
if(b == 0)
{
x = 1;
y = 0;
}
else
{
d = exgcd(b, a % b, y, x);
y -= (a / b)*x;
}
return d;
} LL fpow(LL a, LL n, LL mod)
{
LL res = 1;
while(n)
{
if(n & 1)
res = (res * a % mod + mod) %mod;
a = (a * a % mod + mod) % mod;
n >>= 1;
}
return res;
}
LL p, q, e, n;
LL a[N];
int main()
{
while(~scanf("%lld%lld%lld%lld", &p, &q, &e, &n))
{
for(int i = 0; i < n; i++) scanf("%lld", a + i);
LL mod = p * q;
LL fn = (p - 1) * (q - 1);
for(int i = 0; i < n; i++)
{
LL d = 0 , y = 0;
exgcd(e, fn, d, y);
d = (d + fn) % fn;
a[i] %= mod;
LL ans = fpow(a[i], d, mod);
printf("%c", fpow(a[i], d, mod) % mod);
}
printf("\n");
}
return 0;
}
HDU 1211 EXGCD的更多相关文章
- hdu 1211 逆元
RSA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- hdu 1211 RSA (逆元)
RSA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 1211
水.模拟即可.使用EXGCD求逆元 #include <iostream> #include <cstdio> #include <cstring> #includ ...
- hdu 1211 RSA
// 表示题目意思我是理解了蛮久 英语太水了 //首先这是解密公式 m=c^d mod n// 给你 p q e 然后 n=p*q fn=(p-1)*(q-1)// 给你 e,根据公式 e*d mod ...
- HDU 5377 (Exgcd + 原根)
转载自:大牛 知道一个定理了 a ^ x = y (mod p) ===>> logd(a) * x = logd(y) (mod O(p) ) d 为 p 的 原根, O ...
- HDU 2239 polya计数 欧拉函数
这题模数是9937还不是素数,求逆元还得手动求. 项链翻转一样的算一种相当于就是一种类型的置换,那么在n长度内,对于每个i其循环节数为(i,n),但是由于n<=2^32,肯定不能直接枚举,所有考 ...
- A/B HDU - 1576 (exgcd)
要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1). Input数据的第一行是一个T,表示有T组数据. 每组数据有两 ...
- HDU 5446——Unknown Treasure——————【CRT+lucas+exgcd+快速乘+递推求逆元】
Each test case starts with three integers n,m,k(1≤m≤n≤1018,1≤k≤10) on a line where k is the number o ...
- 题解报告:hdu 1576 A/B(exgcd、乘法逆元+整数快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n ...
随机推荐
- DCOM初步窥探二
1.COM进程透明性表现在“组件对象和客户程序可以拥有各自的空间,也可以共享同一个进程空间”. COM负责把客户的调用正确传到组件对象中,并保证参数传递的正确性. 组件对象和客户代码不必考虑调用传递的 ...
- HDU 5211 Mutiple 水题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5211 题解: 1.筛法: #include<iostream> #include< ...
- Linux下查看apache连接数
1.查看apache当前并发访问数: netstat -an | grep ESTABLISHED | wc -l 对比httpd.conf中MaxClients的数字差距多少. 2.查看有多少个进程 ...
- Spark Transformations介绍
背景 本文介绍是基于Spark 1.3源码 如何创建RDD? RDD可以从普通数组创建出来,也可以从文件系统或者HDFS中的文件创建出来. 举例:从普通数组创建RDD,里面包含了1到9这9个数字,它们 ...
- NFS 它的目的就是想让不同的机器、不同的作业系统可以彼此分享个别的档案啦
NFS即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件, ...
- 免费各种查询API接口
快递查询 http://www.kuaidi100.com/query?type=quanfengkuaidi&postid=390011492112 (PS:快递公司编码:申通"s ...
- 实现全站 HTTPS ,为什么国内网站总是那么slow&&low呀!
1 https://konklone.com/post/switch-to-https-now-for-free# https://theintercept.com/2014/11/20/non-pr ...
- 第76天:jQuery中的宽高
Window对象和document对象的区别 1.window对象表示浏览器中打开的窗口 2.window对象可以省略,比如alert()也可以写成window.alert() Document对象是 ...
- 方法调用时候 传入this 谁调用 传入谁
方法调用时候 传入this 谁调用 传入谁
- bzoj1923[Sdoi2010]外星千足虫(高斯消元)
Description Input 第一行是两个正整数 N, M. 接下来 M行,按顺序给出 Charles 这M次使用“点足机”的统计结果.每行 包含一个“01”串和一个数字,用一个空格隔开.“01 ...