当前位置:网站首页>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;
}边栏推荐
- Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
- 【TkInter】布局管理和事件系统
- FPGA 20个例程篇:9.DDR3内存颗粒初始化写入并通过RS232读取(下)
- Mysql——》BufferPool相关信息
- SATA protocol OOB essay
- 微信小程序逆向
- 使用der格式公钥生成publicKey报错
- 4. Basic type and reference type?
- Data analysis of network security competition of national vocational college skills competition digital forensics-a
- leetcode-记忆化深搜/动态规划v2
猜你喜欢

QT—动画框架

Cryptography knowledge - Introduction to encryption -1

理解动态计算图,requires_grad、zero_grad

Mysqlworkbench performance analysis tool -- Performance dashboard

Rookie colleagues cost me 2K. Did you recite the secret of salary increase? (collect it quickly!)

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

Oracle EBS form common objects and their relationships

Understand corners_ Align, two perspectives for viewing pixels

网络安全80端口—-PHP CGI参数注入执行漏洞

Is the validity period of the root certificate as long as the server SSL certificate?
随机推荐
JS to achieve progress steps (small exercise)
core dump
今日睡眠质量记录79分
全国职业院校技能大赛网络安全竞赛之数据分析数字取证-A
Principle and application of database
卷积神经网络感受野计算指南
OpenGL learning (IV) glut 3D image rendering
Add column by column selection for JTable
The difference between KIB and MIB and KB and MB
redis 数据类型
PCI express physical layer - electrical part
Principle and application of database
L4L7负载均衡
OPENGL学习(五)Modern OpenGL 三角形绘制
Ionic4 learning notes 5-- custom public module
[today in history] July 24: caldera v. Microsoft; Amd announced its acquisition of ATI; Google launches chromecast
Zip compression and decompression
Generate publickey with der format public key and report an error
Typora user manual
狂神redis笔记11