题意: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的更多相关文章

  1. 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-中国剩余定理+同余定 ...

  2. hdu6007 Mr. Panda and Crystal 最短路+完全背包

    /** 题目:hdu6007 Mr. Panda and Crystal 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6007 题意:魔法师有m能量,有n ...

  3. 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 ...

  4. HDU 6240 Server(2017 CCPC哈尔滨站 K题,01分数规划 + 树状数组优化DP)

    题目链接  2017 CCPC Harbin Problem K 题意  给定若干物品,每个物品可以覆盖一个区间.现在要覆盖区间$[1, t]$. 求选出来的物品的$\frac{∑a_{i}}{∑b_ ...

  5. 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}$, 并且能被 ...

  6. ICPC 2016 China Final J. Mr.Panda and TubeMaster【最大费用最大流】

    有一种限制下界强制选的,但是也可以不用 把每个格点拆成两个,一个连s一个连t,对于不是必选的连中间连流量1费用0边表示不选,然后黑白染色,黑点连横着白点连竖着,边权就是这条水管的权值,然后跑最大费用最 ...

  7. China Final J - Mr.Panda and TubeMaster

    和一般的管道不同 不能类似“无限之环”或者“弯弯国”的建图,因为这两个题都是某些位置必须有,或者必须没有 但是本题可以有的位置随意,不能限制某个位置要么流2,要么流0,(实际上可能流了1过去) 所以建 ...

  8. 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 ...

  9. 2018 ccpc final I. Cockroaches

    I. Cockroaches time limit per test6. s memory limit per test256 MB inputstandard input outputstandar ...

随机推荐

  1. 《WEB渗透一.信息收集》

    一.操作系统 Windows服务器  和 Linux服务器. 1.大小写敏感 Windows大小写不敏感 , Linux大小写敏感 如    www.xxxx.com/index.php   和  w ...

  2. dRMT: Disaggregated Programmable Switching, SIGCOMM17

    Reference: dRMT, SIGCOMM 2017 今年的SIGCOMM17会议上,Cisco System和MIT的团队针对RMT模型现有的问题,合作发表了这篇"dRMT: Dis ...

  3. SE91 SAP消息类型

    SE91 SAP消息类型 E:Error W:Warning I  :Information A :Abortion S :Success 标准 : MESSAGE ID sy-msgid TYPE  ...

  4. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(01字典树求最大异或值)

    http://codeforces.com/contest/706/problem/D 题意:有多种操作,操作1为在字典中加入x这个数,操作2为从字典中删除x这个数,操作3为从字典中找出一个数使得与给 ...

  5. Go 字典(Map)

    比较熟悉 Python 的对于字典肯定不会陌生,在 Go 中 map 就是 Python 中字典的概念,它的基本格式是 map[keyType]valueType .map 的读取和设置和 slice ...

  6. for循环 Dictionary

    Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("1" ...

  7. 小程序之从后台取到数据后放入想要的标签list里

    问题:事情是这样的,我有一个标签的功能,but   我怎么吧后台取到的数据放到我想要的标签里呢,而且是那种多个数据自己会加一个标签的内种,效果如下 解决:我们需要用到wx:for   这个东西呢是需要 ...

  8. 【Ruby】【目录 & 引用 & 文件 】

    [[目录]] 当前文件在根目录下一个文件夹下 引用当前文件所在目录上一级目录下某.rb文件 方法一 require File.join(File.dirname(FILE),'..','test_on ...

  9. 网页中Div的打印

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  10. springboot学习之授权Spring Security

    SpringSecurity核心功能:认证.授权.攻击防护(防止伪造身份) 涉及的依赖如下: <dependency> <groupId>org.springframework ...