UVA 568 - Just the Facts
2015-08-24 19:02
363 查看
Description
The expression N!, read as `` N factorial," denotes the product of the first
N positive integers, where N is nonnegative. So, for example,
For this problem, you are to write a program that can compute the last non-zero digit of any factorial for (
). 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.
N, you should read the value and compute the last nonzero digit of N!.
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!.
求n的阶层的最后一位不为0的数
每次不能单单只留最后一位数
因为可能下一位想成加起来能进一
所以要多保留几位
最少要保留五位数
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 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 integerN, 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 valueN, 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
求n的阶层的最后一位不为0的数
每次不能单单只留最后一位数
因为可能下一位想成加起来能进一
所以要多保留几位
最少要保留五位数
#include <stdio.h> int main(){ int n, temp; while (scanf("%d", &n) != EOF) { long long m = 1; for (int i = 1; i <= n; i++) { temp = i; while (temp % 10 == 0) temp /= 10; m *= temp; while (m % 10 == 0) m /= 10; m = m % 100000; } printf("%5d -> %lld\n", n, m % 10); } return 0; }
相关文章推荐
- IOS UITextView自适应高度
- 总线设备驱动模型——platform篇
- poj2503
- IOS UITextView自适应高度
- CSS 之 光进入光
- 安卓程序国际化,手机屏幕适配器
- 腾讯龙界启示录 v2.1.0 安卓版
- mac 常用 终端命令
- HDU 1286 找新朋友【欧拉函数 最基础应用】
- 1083. List Grades
- windows应用程序双机调试方法
- Qt QTreeWidget 树形结构实现
- python嵌套dict的深度遍历合并
- zen-Coding在Notepad++中的使用
- android gif 动画播放
- http的状态响应码
- 链式A+B
- 【转】我的华为面试经历——技术服务
- 排序算法小结
- IOS第12天(2,UINavigationController导航控制器)