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

Re:这样还超时,难道要用查表法...

Posted by zbleach at 2008-09-08 15:25:35 on Problem 1150
In Reply To:这样还超时,难道要用查表法... Posted by:waterine at 2003-07-08 17:54:29
> #include <iostream.h> 
> #include <stdlib.h> 
> 
> int factorial(long int N, long int M) { 
>   long int i, j, result, dp; 
> 
>   dp=0; result = 1; 
> 
>   for(i = N-M+1; i <= N; i++) { 
>     j = i;                 
>     while (! (j % 2)) { j /= 2; dp++; } 
>     while (! (j % 5)) { j /= 5; dp--; } 
>     result = (result * (j % 10)) % 10; 
>   } 
> 
>   for(i = 1; i <= dp; i++) { result = (result * 2) %10; } 
> 
>   return result; 
> } 
> 
> void main() { 
>   long int N, M; 
> 
>   while (1){ 
>       cin >> N >> M; 
>       if(!cin) break; 
>       cout << factorial(N, M) << endl; 
>   } 
> } 

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