| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这样还超时,难道要用查表法...#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator