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

此题要过的话我想只能用Stirling公式了

Posted by Emember at 2008-12-29 21:13:16 on Problem 1423
利用Stirling公式 n! = √2πn (n/e)^n (1+Θ( 1/n))
取n! ≈sqrt(2*pi*n)*(n/e)^n;
对n! 取10的对数log10;
得log10(n!) = log10(sqrt(2*π*n)) + n * log10(n/e);
 e = 2.7182818284590452354
pi = 3.141592653589793239
当 a > 100000时。使用下面的函数求解
double f( int a )
{
	return log10( sqrt( 2 * pi * a ) ) + a * log10( a / e );
}

if( n < 100000 )
{
	for( s=0, i=1; i<=n; i++ )
	s += log10( i );
}
else 
       s = f( n );
printf( "%d\n", (int)(s+1e-7) + 1 );


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