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

随机算法就是这样的啦,有一点点的问题就挂了

Posted by frkstyc at 2005-07-09 22:17:23 on Problem 1811
In Reply To:Pollard部分,怎么可能有死循环哦?! Posted by:queyue2004 at 2005-07-09 22:11:29
> 
> __int64 PollardRho (const __int64 &c,const __int64 &test)
> {
> 	__int64 y,x,gcd;
> 	int i,k;
> 
> 	y = x = rand () % test;
> 	i = 1;
> 	k = 2;
> 	do
> 	{
> 		i++;
> 		gcd = Gcd (2 * test + y - x,test);
> 		if (gcd > 1 && gcd < test)
> 		{
> 			return gcd;
> 		}
> 		if (i == k)
> 		{
> 			y = x;
> 			k *= 2;
> 		}
> 		x = (x * x + test - c) % test;
> 	}while (x != y);
> 	
> 	return test;
> }
> 		
> //----------------------------------------------
> 
> //----------------------------------------------
> void Rho (const __int64 &test)
> {
> 	__int64 n;
> 
> 	if (MillerRabin (test,2))
> 	{
> 		if (test < min)
> 		{
> 			min = test;
> 		}
> 	}
> 	else
> 	{		
> 		n = PollardRho (rand() % (test - 1) + 1,test);
> 	                if (n < test)
> 		{
> 	     	       Rho (n);
> 	    	       Rho (test / 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