首页 > 其他 > 详细

质因子分解(Pollard_Rho法)

时间:2017-08-16 11:00:47      阅读:216      评论:0      收藏:0      [点我收藏+]
LL Pollard_Rho(LL n, LL c) {
    LL x, y, d;
    LL i = 1, k = 2;
    x = y = rand() % n;
    do {
        i++;
        d = gcd(n + y - x, n);
        if(d > 1 && d < n) return d;
        if(i == k) {
            y = x;
            k <<= 1;
        }
        x = (mul_mod(x, x, n) + n - c) % n;
    } while(y != x);
    return n;
}
void rhoAll(LL n) {
    if(n <= 1) return;
    if(isPrime(n)) {
        fac.push_back(n);
        return;
    }
    LL t = n;
    while(t >= n)
        t = Pollard_Rho(n, rand() % (n-1) + 1);
    rhoAll(t);
    rhoAll(n/t);
    return;
}

 

质因子分解(Pollard_Rho法)

原文:http://www.cnblogs.com/sapphirebitter/p/7371855.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!