Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

帮我看看pollard怎么改进,和算法导论的,实用算法分析的差不多

Posted by sunmoonstar_love at 2005-07-01 23:00:02 on Problem 2447
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator