• loj2045 「CQOI2016」密钥破解


    CQOI 板子大赛之 pollard rho

    #include <iostream>
    #include <cstdio>
    using namespace std;
    typedef long long ll;
    ll e, N, c, jzm, p, q, r, d, n;
    ll gcd(ll a, ll b){
    	return !b?a:gcd(b,a%b);
    }
    ll mul(ll a, ll b, ll p){
    	ll re=0;
    	while(b){
    		if(b&1)	re = (re + a) % p;
    		a = (a + a) % p;
    		b >>= 1;
    	}
    	return re;
    }
    ll pollardRho(){
    	ll x=2, y=2;
    	while(true){
    		x = (mul(x,x,N)+jzm) % N;
    		y = (mul(y,y,N)+jzm) % N;
    		y = (mul(y,y,N)+jzm) % N;
    		if(x==y)	return 1;
    		ll re=gcd(x>y?x-y:y-x, N);
    		if(re>1)	return re;
    	}
    }
    ll exgcd(ll a, ll b, ll &x, ll &y){
    	if(!b){
    		x = 1;
    		y = 0;
    		return a;
    	}
    	ll re=exgcd(b, a%b, x, y);
    	ll z=x;
    	x = y;
    	y = z - (a / b) * y;
    	return re;
    }
    ll ksm(ll a, ll b, ll p){
    	ll re=1;
    	while(b){
    		if(b&1)	re = mul(re, a, p);
    		a = mul(a, a, p);
    		b >>= 1;
    	}
    	return re;
    }
    int main(){
    	cin>>e>>N>>c;
    	do{
    		jzm++;
    		p = pollardRho();
    	}while(p==1);
    	q = N / p;
    	r = (p - 1) * (q - 1);
    	ll dddddd;
    	exgcd(e, r, d, dddddd);
    	d = (d % r + r) % r;
    	n = ksm(c, d, N);
    	cout<<d<<" "<<n<<endl;
    	return 0;
    }
    
  • 相关阅读:
    ASP.NET使用SWFUpload上传大文件教学
    Gridview自定义分页(转载)
    扩展GridView之个性分页(转载)
    畅通工程
    一个人的旅行
    Stockbroker Grapevine
    Arbitrage
    More is better
    HDU Today
    Minimum Transport Cost
  • 原文地址:https://www.cnblogs.com/poorpool/p/8954819.html
Copyright © 2020-2023  润新知