当前位置:网站首页>2022 Hangdian multi school second session 1009 shuangq (Mathematics)
2022 Hangdian multi school second session 1009 shuangq (Mathematics)
2022-07-24 18:48:00 【Dusk of fools】
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
The main idea of the topic :
For a given P And its inverse Q as well as enc, Seeking the cause P seek Q Of mod, And work out P*enc%mod
Ideas :
For each pair PQ There is a unique prime factor M(M>P&&M>Q) bring P*Q-1==K*M( The falsification is shown in the figure below ), All you have to do is P*Q-1 Find out the prime factor of

Code implementation :
#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;// Make sure that every time i All prime numbers
M=i;// It must be a prime number
}
if(KM>1) M=KM;
if(M>Q&&M>P){
raw=enc*Q%M;
cout<<enc*Q%M<<endl;
}
else puts("shuanQ");
}
return 0;
}边栏推荐
- MySQL -- implicit conversion of data type
- Sqoop
- Ionic4 learning notes 3
- Sqoop
- FPGA 20 routines: 9. DDR3 memory particle initialization write and read through RS232 (Part 1)
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
- Ionic4 learning notes 1
- QT - animation frame
- 使用 tftp 无法向服务器上传文件问题解决
- Ionic4 learning notes 11 - popular goods display of an East Project
猜你喜欢

EasyUI framework dialog repeated loading problem

Cf. bits and pieces (subset pressing DP + pruning)

The difference between static method and instance method

今日睡眠质量记录79分

Valentine's Day gift ----- use her photos and our chat records to generate word clouds~

Inoic4 learning notes 2

狂神redis笔记11

matplotlib

EasyUI adds row level buttons to the DataGrid

Ionic4 learning notes 5-- custom public module
随机推荐
OPENGL学习(四)GLUT三维图像绘制
Vsftpd2.3.4-端口渗透 6200 irc_3281_backdoor
投资的新阶段
无关的表进行关联查询及null=null条件
What are the benefits of knowledge management in enterprises?
FPGA 20 routines: 9. DDR3 memory particle initialization write and read through RS232 (Part 1)
MySQL optimization series (2) -- InnoDB important parameter optimization
Data analysis of network security competition of national vocational college skills competition digital forensics-a
9. BOM object?
使用der格式公钥生成publicKey报错
Sqoop
The problem that files cannot be uploaded to the server using TFTP is solved
vim相关介绍
Add column by column selection for JTable
Type-C边充边听PD协议芯片
Segment tree merge board
Some buckles
Attack and defense world novice zone PWN
[today in history] July 24: caldera v. Microsoft; Amd announced its acquisition of ATI; Google launches chromecast
Latex数学公式