| ||||||||||
| 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怎么改进,和算法导论的,实用算法分析的差不多In Reply To:用eulerphi我就笨了,用ext euclid省了很多代码,又快了一些 Posted by:frkstyc at 2005-07-01 22:42:14 llong pollard(llong n)
{//返回 n 的一个质因子
srand(rand()+n);
llong i,k,d,c,x,y;
i = 1; k = 2;
y = x = abs(rand()%(n-1))+1;
c = abs(rand()%(n-1))+1;
do
{
i++;
d = GCD(n+y-x,n);
if(d>1&&d<n)
return d;
if(i==k)
{
y = x;
k *= 2;
}
// x = ((x%n)*x)%n - c + n;
x = mul_mod(x,x,n) - c + n;
// c = abs(rand()%(n-1))+1;
}while(y!=x);
return n;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator