题意: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#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 #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 #define pil pair #define pli pair #define pii pair #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 inline T const& MAX(T const &a,T const &b){return a>b?a:b;}template inline T const& MIN(T const &a,T const &b){return a >=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;}/****************************************/