| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这个 pollard_p-1In Reply To:再贴个fermat Posted by:sunmoonstar_love at 2005-08-17 23:32:24 unsigned long pollard_p1(unsigned long n)
{
unsigned long gcd_result;
do {
// b is the smoothness bound,
// all the prime factors of
// n must be <= b
unsigned int b = 1234;
// Generate a random number
// 2 <= a <= n-1
unsigned long a = true_random(n-3) + 2;
unsigned long d = gcd(a, n);
if (d >= 2) return d;
double l;
unsigned long inner_pow;
unsigned long outer_pow;
for (unsigned int q=2; q<=b; q++) {
l = log(n)/log(q);
inner_pow = pow(a, q);
outer_pow = pow(inner_pow, l);
a = outer_pow % n;
}
gcd_result = gcd(a-1, n);
} while(gcd_result == n);
return gcd_result;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator