• (CCPC-Final 2018)K


    题意: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*emod{r}=1),(c^dmod{n}=f)
    证明:(c=f^e%n),(f^{d*e}=f^{d*emod(phi(n))}mod{n}=f^{d*emod{(p-1)*(q-1)}}mod n=fmod{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
    ",++cas,qpow(c,x,n));
        }
        return 0;
    }
    /********************
    
    ********************/
    
  • 相关阅读:
    ADT上跑java application
    GIT 用RSA加密方式来记住密码
    android中listView下有Button按钮始终在最底部
    Android学习:导入工程时报错The import android cannot be resolved
    Preference的使用
    MySQL查询时,查询结果如何按照where in数组排序
    MySQL创建民族表的SQL语句
    PHP 使用GD库合成带二维码和圆形头像的海报步骤以及源码实现
    使用file_get_contents()和curl()抓取网络资源的效率对比
    常用正则表达式整理(持续更新中)
  • 原文地址:https://www.cnblogs.com/acjiumeng/p/10522570.html
Copyright © 2020-2023  润新知