(CCPC-Final 2018)K - Mr. Panda and Kakin
题意:x是\([1e5,1e9]\)的随机数,p是小于x的最大素数,q是大于等于x的最小素数,\(n=pq\),\(c=f^{2^{30}+3}\mod{n}\),给n和c求f
题解:rsa解密,首先在\(sqrt(n)\)附近找到p和q,让\(r=(p-1)*(q-1)\),\(e=2^{30}+3\),\(d*e\mod{r}=1\),\(c^d\mod{n}=f\)
证明:\(c=f^e%n\),\(f^{d*e}=f^{d*e\mod(\phi(n))}\mod{n}=f^{d*e\mod{(p-1)*(q-1)}}\mod n=f\mod{n}\)
需要O(1)快速乘
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000009
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;}
inline void add(ll &a,ll b,ll c){a+=b;if(a>=c)a-=c;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qm(ll a,ll b,ll c){ll ans=0;while(b){if(b&1)add(ans,a,c);add(a,a,c);b>>=1;}return ans;}
inline ll qpow(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c);b>>=1;}return ans;}
using namespace std;
const ull ba=233;
const db eps=1e-10;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=500000+10,maxn=100000+10,inf=0x3f3f3f3f;
inline ll exgcd(ll a,ll b,ll &x,ll &y)
{
if(!b){x=1,y=0;return a;}
ll ans=exgcd(b,a%b,x,y);
ll t=x;x=y;y=t-a/b*y;
return ans;
}
int main()
{
ll a=(1ll<<30)+3;
int T,cas=0;scanf("%d",&T);
while(T--)
{
ll n,c;scanf("%lld%lld",&n,&c);
ll p=sqrt(n),q;
while(n%p!=0)p--;
q=n/p;
ll b=(p-1)*(q-1),x,y;
exgcd(a,b,x,y);
x=(x%b+b)%b;
printf("Case %d: %lld\n",++cas,qpow(c,x,n));
}
return 0;
}
/********************
********************/
(CCPC-Final 2018)K - Mr. Panda and Kakin的更多相关文章
- 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定理
2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定 ...
- hdu6007 Mr. Panda and Crystal 最短路+完全背包
/** 题目:hdu6007 Mr. Panda and Crystal 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6007 题意:魔法师有m能量,有n ...
- H - Mr. Panda and Birthday Song Gym - 101775H (动态规划)
Mrs. Panda’s birthday is coming. Mr. Panda wants to compose a song as gift for her birthday. It is k ...
- HDU 6240 Server(2017 CCPC哈尔滨站 K题,01分数规划 + 树状数组优化DP)
题目链接 2017 CCPC Harbin Problem K 题意 给定若干物品,每个物品可以覆盖一个区间.现在要覆盖区间$[1, t]$. 求选出来的物品的$\frac{∑a_{i}}{∑b_ ...
- Codeforces Gym 101775D Mr. Panda and Geometric Sequence(2017-2018 ACM-ICPC Asia East Continent League Final,D题,枚举剪枝)
题目链接 ECL-Final 2017 Problem D 题意 给定$2*10^{5}$组询问,每个询问求$l$到$r$之间有多少个符合条件的数 如果一个数小于等于$10^{15}$, 并且能被 ...
- ICPC 2016 China Final J. Mr.Panda and TubeMaster【最大费用最大流】
有一种限制下界强制选的,但是也可以不用 把每个格点拆成两个,一个连s一个连t,对于不是必选的连中间连流量1费用0边表示不选,然后黑白染色,黑点连横着白点连竖着,边权就是这条水管的权值,然后跑最大费用最 ...
- China Final J - Mr.Panda and TubeMaster
和一般的管道不同 不能类似“无限之环”或者“弯弯国”的建图,因为这两个题都是某些位置必须有,或者必须没有 但是本题可以有的位置随意,不能限制某个位置要么流2,要么流0,(实际上可能流了1过去) 所以建 ...
- 2016EC Final F.Mr. Panda and Fantastic Beasts
题目大意 \(T(1\leq T\leq42)\)组数据,给定\(n(2\leq n\leq 50000)\)个字符串\(S_{i}(n\leq\sum_{i=1}^{n}S_{i}\leq 2500 ...
- 2018 ccpc final I. Cockroaches
I. Cockroaches time limit per test6. s memory limit per test256 MB inputstandard input outputstandar ...
随机推荐
- 如何查看sonarqube的版本
Server Logs & System Info The System Info page is found at Administration > System. It gives ...
- FancyBox的使用技巧 (汇总)
http://note.youdao.com/share/?id=1c8373249f523529a6b6dcde60777400&type=note#/
- MySQL删除数据库时无响应解决办法
删除远程主机上MySQL中的一个数据库时,远程主机一直在响应,无法正常删除. 这个问题的解决办法如下:在远程主机上登录MySQL,执行show full processlist;观察state和inf ...
- SQLServer2014 安装错误:等待数据库引擎恢复句柄失败
查了很多资料最后靠百度百科里的一票报道彻底解决困难.在次发表一下以便给后人排忧解难 已下为百度连接 https://jingyan.baidu.com/article/7908e85cb24c19af ...
- 【译】第16节---数据注解-Table
原文:http://www.entityframeworktutorial.net/code-first/table-dataannotations-attribute-in-code-first.a ...
- HDU 6215 Brute Force Sorting(链表)
http://acm.hdu.edu.cn/showproblem.php?pid=6215 题意:给出一个序列,对于每个数,它必须大于等于它前一个数,小于等于后一个数,如果不满足,就删去.然后继续去 ...
- Perl中命令行参数以及打开管道文件
打开管道文件 Linux提供了管道机制,可以方便应用程序之间的数据传递.在Perl中,扣开和使用管道可采用如下形式的open函数: open(Filehandle,”丨 CMD”); 其中 ...
- Codeforces 769D k-Интересные пары чисел
题目链接:http://codeforces.com/contest/769/problem/D 搜索题 考虑这些数的值域较小,直接${O(2^{k})}$次方枚举每个数字二进制位上是否改变,剪枝一下 ...
- P1547 Out of Hay
传送门 练习 只是一个最小生成树的水题,拿来练练模板 AC代码: #include<iostream> #include<cstdio> #include<alg ...
- python中的print()、str()和repr()的区别
print()函数,我们可以看出,在Python IDLE中直接输入的字符串都是有类型的,而print打印后的字符串相当于一串文字,把字符串的引号也省略了,没有类型 print()函数,生成可读性更好 ...