当前位置:网站首页>2022杭电多校第二场1009 ShuanQ(数学)
2022杭电多校第二场1009 ShuanQ(数学)
2022-07-24 18:35:00 【愚者的黄昏】
CX is a programmer of a mooc company. A few days ago, he took the blame for leakage of users' data. As a result, he has to develop an encryption algorithm, here is his genius idea.
First, the protocol specifies a prime modulus M, then the server generates a private key P, and sends the client a public key Q. Here Q=P−1,P×Q≡1modM.
Encryption formula: encrypted_data=raw_data×PmodM
Decryption formula: raw_data=encrypted_data×QmodM
It do make sense, however, as a master of number theory, you are going to decrypt it.You have intercepted information about P,Q,encrypted_data, and M keeps unknown. If you can decrypt it, output raw_data, else, say "shuanQ" to CX.
Input
First line has one integer T(T≤20), indicating there are T test cases. In each case:
One line has three integers P,Q,encrypted_data. (1<P,Q,encrypted_data≤2×106)
It's guaranteed that P,Q,encrypted_data<M.
Output
In each case, print an integer raw_data, or a string "shuanQ".
Sample Input
2
5 5 5
6 6 6
Sample Output
shuanQ
1
题目大意:
对于给定的P及其逆元Q以及enc,求由P求Q的mod,并算出P*enc%mod
思路:
对于每对PQ都有唯一的质因数M(M>P&&M>Q)使得P*Q-1==K*M(证伪如下图),这样只需要把P*Q-1的质因数求出来即可

代码实现:
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=100010;
typedef long long LL;
int main(){
int t;
cin>>t;
while(t--){
LL P,Q,enc,raw=-1;
cin>>P>>Q>>enc;
LL KM=P*Q-1,M;
for(LL i=2;i*i<=KM;i++){
if(KM%i) continue;
while(KM%i==0) KM/=i;//保证每次i都是质数
M=i;//必定是质数
}
if(KM>1) M=KM;
if(M>Q&&M>P){
raw=enc*Q%M;
cout<<enc*Q%M<<endl;
}
else puts("shuanQ");
}
return 0;
}边栏推荐
- Type-C PD protocol chip while charging and listening
- Ionic4 learning notes 5-- custom public module
- Understand corners_ Align, two perspectives for viewing pixels
- The assignment and answer of the "Cyberspace Security" competition of the 2020 secondary vocational group in Zhejiang Province (flag)
- 线段树合并板子
- Analysis of several possible causes of 0xc0000005 memory violation
- Cf. bits and pieces (subset pressing DP + pruning)
- Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
- 【TkInter】常用组件(一)
- 2. JS variable type conversion, automatic conversion, manual conversion, what is the difference between parseint(), parsefloat(), number()?
猜你喜欢

Make C #

无关的表进行关联查询及null=null条件

["code" power is fully open, and "chapter" shows strength] list of contributors to the task challenge in the first quarter of 2022

Sword finger offer 21. adjust the array order so that odd numbers precede even numbers

怎么解决idea中yaml无法识别或者飘红?

【微信小程序开发】自定义tabBar案例(定制消息99+小红心)

轻松学Pytorch-迁移学习实现表面缺陷检查

永恒之蓝MS17-010exp复现

Escape character in JS?

剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
随机推荐
We have to understand the four scopes: application, session, request and page
The difference between KIB and MIB and KB and MB
缺失值处理
使用der格式公钥生成publicKey报错
Sword finger offer 21. adjust the array order so that odd numbers precede even numbers
卷积神经网络感受野计算指南
CF lomsat gelral (heuristic merge)
Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
Tree chain partition board
MySQL -- implicit conversion of data type
Wechat applet reverse
今日睡眠质量记录79分
Mysql——》BufferPool相关信息
Ionic4 learning notes 1
["code" power is fully open, and "chapter" shows strength] list of contributors to the task challenge in the first quarter of 2022
Zip compression and decompression
Revocable search board
Template inheritance and import
Go小白实现一个简易的go mock server
Maximum sum and promotion of continuous subarrays (2)