| ||||||||||
| 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 | |||||||||
第二个0ms过!//============================================================================
// Name : main1604.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <cmath>
using namespace std;
int numof2(int& n){
int cnt = 0;
while((n/2)*2 == n) {
n = n/2;
cnt++;
}
return cnt;
}
int numof5(int& n){
int cnt = 0;
while((n/5)*5 == n) {
n = n/5;
cnt++;
}
return cnt;
}
int p2(int n){
if(n == 0) return 1;
switch(n%4){
case 0: return 6;
case 1: return 2;
case 2: return 4;
case 3: return 8;
}
}
int main() {
int n;
int n2[10001] = {0}, n5[10001] = {0}, qt[10001] = {1, 0};
int max = 0;
while(cin >> n){
int res;
if(n > max){
for(int i = max + 1; i <= n; i++){
int temp = i;
n2[i] = n2[i-1] + numof2(temp);
n5[i] = n5[i-1] + numof5(temp);
qt[i] = (qt[i-1] * temp) % 10;
}
max = n;
}
res = (p2(n2[n] - n5[n]) * qt[n]) % 10;
int spaces = 4 - (int)log10(n * 1.0);
for(int i = 0; i < spaces; i++) cout << " ";
cout << n << " -> " << res << endl;
}
//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator