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 ...
随机推荐
- "Hello World!"团队第十次会议
Scrum会议 今天是我们"Hello World!"团队第十次召开会议,博客内容是: 1.会议时间 2.会议成员 3.会议地点 4.会议内容 5.todo list 6.会议照片 ...
- 周总结<4>
经过了一周的学习,我们在html以及C语言方面又有的新的知识点的学习. html 自习表格,函数等 C语言 哈弗曼编码 Html案例: 一. <!DOCTYPE html PUBLIC &quo ...
- C语言文法翻译
<程序>→<外部声明>|<程序><外部声明> <外部声明>→<函数定义>|<声明> <函数定义>→< ...
- Linux的压缩/解压缩文件处理 zip & unzip
Linux的压缩/解压缩命令详解及实例 压缩服务器上当前目录的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前目录 unzip filename.zip 另:有些服 ...
- (转)ActiveMQ的重连机制
花了一天的时间,终于搞明白了我的疑问. failover://(tcp://localhost:6168)?randomize=false&initialReconnectDelay=100& ...
- 实现全站 HTTPS ,为什么国内网站总是那么slow&&low呀!
1 https://konklone.com/post/switch-to-https-now-for-free# https://theintercept.com/2014/11/20/non-pr ...
- SSH管理(重启 停止 运行 安装)centos7
下面整理经常用到管理SSH服务的命令,方便复制哈. SSH服务状态 systemctl status sshd.service SSH运行命令 service sshd start SSH重启命令 s ...
- mvc4扩展方法
制作扩展方法,方便网页中使用,下面做了两个例子 using System; using System.Collections.Generic; using System.Linq; using Sys ...
- python的N个小功能(高斯模糊原理及实践)
原理: 二维高斯函数 1) 为了计算权重矩阵,需要设定σ的值.假定σ=1.5,则模糊半径为1的权重矩阵如下: 2) 这9个点的权重总和等于0.4787147,如果只计算 ...
- 【转】Oracle 查询库中所有表名、字段名、表名说明、字段名说明
转自 :http://gis-conquer.blog.sohu.com/170243422.html 查询所有表名:select t.table_name from user_tables t; 查 ...