"Fast factorization" Pollard ' s Rho algorithm

Source: Internet
Author: User

Algorithm Purpose

Give a number n and quickly extract a factor of N.

algorithm based on: Birthday Paradox

Before you tell the birthday paradox, look at one thing first.
Given the number of [1..1000], the probability of selecting a number from any of the K is 1 + 。
But if you choose two numbers p,q ask for their difference is k, is the probability of |p-q|=k is probably 1 - , because to go to absolute value.
Continue down, select the number of L, so that they have two number of the difference between k, then the probability will be larger with L and will become larger, eventually approaching 1.
Next is the birthday paradox:
We randomly selected a student whose birthday is the probability of April 1 for [1..365]
This is the equivalent of randomly selecting a number in [1..365], which is the probability of 90?
So we're back to the question above.
We randomly selected K (k≥2) Individuals, what is the probability of their birthdays being equal (the difference is 0)?
We can see that k = 10 when there is probably a 11% chance of having two people birthday the same situation,
and k = 23 o'clock, the possibility to increase to 50%, if a class total of 57 people, and the likelihood of l=57 has reached 99%, almost certainly, a class must have two classmates of the birth date is the same, and so many years of schooling came, the probability "seems" is not correct, This is the paradox.

Pollard ' s Rho algorithm

So, with this metaphysical paradox, we can quickly decompose n at random, 2333.
There is a random function f (x) = (x*x+d)%n,d=rand (). Then each random number and the last random number of the difference with N to go to a maximum common factor, and then judge the better.
But what if you can't find the number that fits and then you die.
We can use the Floyd invented by the wit algorithm, because I a=f (a), and then find a b=f (f (b)), if there is a moment a=b then exit the loop, because B is at twice times the speed of the go, when B catch up with a, then B has at least finished a lap.
Complexity O ( n 1 4 ), appears O (metaphysics).

Code

Random function f

x){    int u=rand();    return (cheng(x,x,n)+po)%n;}

Pollard ' s Rho algorithm

A=0; b=1; po=Rand()%n+1; while(1) {a=b=Rand()%n+1; while(1) {a=f (a); B=f (f (b));if(a==b) Break; ll ui=ABS(B-A); ll TT=GCD (ui,n);if(tt==1|| Tt==n)Continue;if(tt>1) {P=tt; Break; }} po--;if(p) Break; }

"Fast factorization" Pollard ' s Rho algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.