嘟嘟嘟




这题我读了两遍才懂,然后感觉要解什么高次同余方程……然后我又仔细的看了看题,发现只要求得\(p\)和\(q\)就能求出\(r\),继而用exgcd求出\(d\),最后用快速幂求出\(n\)。

再看看这个数据范围,用Pollard-Rho最适合不过了。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
#include<ctime>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define In inline
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
//const int maxn = ;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = (ans << 1) + (ans << 3) + ch - '0'; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} ll e, N, c, r; In ll mul(ll a, ll b, ll mod)
{
ll d = ((long double)a / mod * b + 1e-8);
ll r = a * b - d * mod;
return r < 0 ? r + mod : r;
}
In ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
In ll f(ll x, ll a, ll mod) {return (mul(x, x, mod) + a) % mod;} int a[] = {2, 3, 5, 7, 11};
const int M = (1 << 7) - 1;
In ll find(ll n)
{
for(int i = 0; i < 5; ++i) if(n % a[i] == 0) return a[i];
ll x = rand(), y = x, a = rand() % (n - 2) + 2, t = 1;
for(int k = 2;; k <<= 1, y = x)
{
ll p = 1;
for(int i = 1; i <= k; ++i)
{
x = f(x, a, n);
p = mul(p, abs(x - y), n);
if(!(i & M))
{
t = gcd(p, n);
if(t > 1) break;
}
}
if(t > 1 || (t = gcd(p, n)) > 1) break;
}
return t;
}
In ll pollard_rho(ll x)
{
ll p = x;
while(p == x) p = find(x);
return p;
} In void exgcd(ll a, ll b, ll& x, ll& y, ll& t)
{
if(!b) t = a, x = 1, y = 0;
else exgcd(b, a % b, y, x, t), y -= a / b * x;
} In ll quickpow(ll a, ll b, ll mod)
{
a %= mod;
ll ret = 1;
for(; b; b >>= 1, a = mul(a, a, mod)) //别忘了这里也会爆long long
if(b & 1) ret = mul(ret, a, mod);
return ret;
} int main()
{
srand(time(0));
e = read(), N = read(), c = read();
ll p = pollard_rho(N), q = N / p; ll r = (p - 1) * (q - 1);
ll d, y, t;
exgcd(e, r, d, y, t);
t = r / t;
d = (d % t + t) % t;
ll n = quickpow(c, d, N);
write(d), space, write(n), enter;
return 0;
}

[CQOI2016]密钥破解的更多相关文章

  1. LG4718 【模板】Pollard-Rho算法 和 [Cqoi2016]密钥破解

    Pollard-Rho算法 总结了各种卡常技巧的代码: #define int long long typedef __int128 LL; IN int fpow(int a,int b,int m ...

  2. BZOJ4522:[CQOI2016]密钥破解(Pollard-Rho,exgcd)

    Description 一种非对称加密算法的密钥生成过程如下: 1. 任选两个不同的质数 p ,q 2. 计算 N=pq , r=(p-1)(q-1) 3. 选取小于r ,且与 r 互质的整数 e  ...

  3. BZOJ 4522: [Cqoi2016]密钥破解

    http://www.lydsy.com/JudgeOnline/problem.php?id=4522 题目:给你RSA密钥的公钥和密文,求私钥和原文,其中\(N=pq\le 2^{62}\),p和 ...

  4. BZOJ4522: [Cqoi2016]密钥破解

    pollard's rho模板题. 调参调到160ms无能为力了,应该是写法问题,不玩了. #include<bits/stdc++.h> using namespace std; typ ...

  5. BZOJ 4522: [Cqoi2016]密钥破解 (Pollard-Rho板题)

    Pollard-Rho 模板 板题-没啥说的- 求逆元出来后如果是负的记得加回正数 CODE #include<bits/stdc++.h> using namespace std; ty ...

  6. BZOJ 4522: [Cqoi2016]密钥破解 exgcd+Pollard-Rho

    挺简单的,正好能再复习一遍 $exgcd$~ 按照题意一遍一遍模拟即可,注意一下 $pollard-rho$ 中的细节. #include <ctime> #include <cma ...

  7. 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)

    4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 290  Solved: 148[Submit][Status ...

  8. LibreOJ2045 - 「CQOI2016」密钥破解

    Portal Description 给出三个正整数\(e,N,c(\leq2^{62})\).已知\(N\)能表示成\(p\cdot q\)的形式,其中\(p,q\)为质数.计算\(r=(p-1)( ...

  9. Visio Premium 2010密钥+破解激活方法

    Visio Premium 2010密钥+破解激活方法: 在安装时能够使用下面密钥: GR24B-GC2XY-KRXRG-2TRJJ-4X7DC VWQ6G-37WBG-J7DJP-CY66Y-V27 ...

随机推荐

  1. [转]微擎应用笔记3--manifest.xml文件使用说明

    本文转自:https://blog.csdn.net/seven_north/article/details/79508121 微擎在安装或卸载模块时会根据manifest.xml生成(或删除)数据库 ...

  2. Spring MVC 学习总结(十)——Spring+Spring MVC+MyBatis框架集成(IntelliJ IDEA SSM集成)

    与SSH(Struts/Spring/Hibernate/)一样,Spring+SpringMVC+MyBatis也有一个简称SSM,Spring实现业务对象管理,Spring MVC负责请求的转发和 ...

  3. Java基础——Oracle(七)

    一.概述 pl/sql (procedural lanaguage/sql)是 oracle 在标准 sql 上的扩展 .不仅允许嵌入sql 语言,还可以定义变量和常量,允许使用条件语句和循环语句,允 ...

  4. 【Dubbo&&Zookeeper】5、dubbo总结和学习资料汇总

    Dubbo学习资料 阿里巴巴分布式服务框架 Dubbo 团队成员梁飞专访 RPC介绍 什么是RPC? RPC(Remote Procedure Call)远程过程调用.见名知意 - 从远程主机调用一个 ...

  5. canvas-4fillstyle.html

    fillStyle color gradient pattern image canvas video strokeStyle

  6. blfs(systemv版本)学习笔记-编译安装openssh软件包

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! openssh项目地址:http://www.linuxfromscratch.org/blfs/view/8.3/postlf ...

  7. java.io.IOException No space left on device

    磁盘空间不足 1.df -k,发现程序所在的工作目录/data,居然到了100%. 1604050 free allocated Kb 535144219 used allocated Kb 100 ...

  8. 2018-02-04 AppleScript类自然语言与非英语语法设计

    最早知晓是之前C#中文版的github讨论里提到了AppleScript有多语言版. 昨天想起, 觉得它毕竟是为数不多(仅有的?)大公司开发的非英语语法的编程语言, 不禁好奇它的前世今生. 于是作了一 ...

  9. CSS中的行内元素和块级元素

    我们在构造页面时,会发现有的元素是上下排列的,而有的则是横向排列的,这是为啥子呢   看看上图,我们也没给他设置啥子属性咋就不一样了,其实是因为每个元素都有默认的 display 属性,比如 div ...

  10. PHP与.Net的区别(一)接口

    一.关于接口成员 PHP的接口成员只能包括两种: 1.函数签名 2.常量 .Net的接口成员只能包括三种: 1.函数签名 2.属性(注意:是属性,不是字段) 3.事件 4.索引器(也叫有参属性)