poj 1604 Just the Facts

it2024-04-12  8

Just the Facts

Time Limit: 1000MS Memory Limit: 65536K

Total Submissions: 7334 Accepted: 3881

Description

The expression N!, read as "N factorial," denotes the product of the first N positive integers, where N is nonnegative. So, for example,

N N! 0 1 1 1 2 2 3 6 4 24 5 120 10 3628800

For this problem, you are to write a program that can compute the last non-zero digit of any factorial for (0 <= N <= 10000). For example, if your program is asked to compute the last nonzero digit of 5!, your program should produce "2" because 5! = 120, and 2 is the last nonzero digit of 120.

Input

Input to the program is a series of nonnegative integers not exceeding 10000, each on its own line with no other letters, digits or spaces. For each integer N, you should read the value and compute the last nonzero digit of N!.

Output

For each integer input, the program should print exactly one line of output. Each line of output should contain the value N, right-justified in columns 1 through 5 with leading blanks, not leading zeroes. Columns 6 - 9 must contain " -> " (space hyphen greater space). Column 10 must contain the single last non-zero digit of N!.

Sample Input

1 2 26 125 3125 9999

Sample Output

1 -> 1 2 -> 2 26 -> 4 125 -> 8 3125 -> 2 9999 –> 8 1: #include<iostream> 2: using namespace std; 3: int main() 4: { 5: int n; 6: int i; 7: int res; 8: while(cin>>n) 9: { 10: res=1; 11: for(i=1;i<=n;i++) 12: { 13: res=res*i; 14: while(res%10==0) 15: { 16: res=res/10; 17: } 18: res=res%100000; 19: } 20: printf("%5.d -> %d\n",n,res%10); 21: } 22: return 0; 23: } 24:

转载于:https://www.cnblogs.com/w0w0/archive/2011/11/21/2257661.html

相关资源:数据结构—成绩单生成器
最新回复(0)