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

再贴个fermat

Posted by sunmoonstar_love at 2005-08-17 23:32:24
In Reply To:这个pollard_rho把我搞无语了 Posted by:sunmoonstar_love at 2005-08-17 23:25:51
int fermat(int n)
{
    int result;

    do {    
        int x = (int)ceil(sqrt(0.0+n));
        int y = x*x - n;
    
        while(!issqrt(y)){
            y = y + 2*x + 1;
            x += 1;
        }
        // This method could easely
        // return the other prime too
        // (x-sqrt(y));
        result = int(x+sqrt(0.0+y)+0.5);
    } while(result == n);

    return result;
}

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