swustoj dearway's problem(0240)
来源:互联网 发布:花千骨衣服淘宝 编辑:程序博客网 时间:2024/06/05 03:00
请编写一个程序,输出N的阶乘的十进制表示中从最末一个非0位开始自低位向高位数的第K位。
其中:0<=N<=10000,1<=K<=5
例如:N=4,K=2,结果是2(4!=24) N=6,K=1,结果为2(6!=720)
其中:0<=N<=10000,1<=K<=5
例如:N=4,K=2,结果是2(4!=24) N=6,K=1,结果为2(6!=720)
Description
有多组输入数据。
每组数据输入两个整数N,K
每组数据输入两个整数N,K
Input
输出每行一个整数,即测试数据的结果。
Output
1
2
3
4 2
6 1
Sample Input
1
2
3
2
2
Sample Output
#include<iostream>#include<stdio.h>#include<algorithm>using namespace std;#define _max 100000int main(){int n, k;int ans = 1;while (cin >> n >> k){long long sum = 1;for (int i = n; i >= 2; i--){sum *= i;while (sum % 10 == 0){sum /= 10;}if (sum > _max)//每次只保存后五位非零数据sum %= _max;}//cout << sum << endl;while (k--){ans = sum % 10;sum /= 10;}cout << ans << endl;}return 0;}
0 0
- swustoj dearway's problem(0240)
- dearway's problem
- SwustOj A simple problem(0093)
- Problem S
- Problem-S
- Problem S
- swustoj---1091
- swustoj(667)
- Vivian's Problem
- Eva's Problem
- PKU_ACM_1658_Eva's Problem
- Little Boy's Problem
- pku1899Farmer Bill's Problem
- Shoemaker's Problem
- iew's problem
- poj1658 Eva's Problem!
- Painter's Problem POJ1681
- 10026 - Shoemaker's Problem
- JAVA反射机制(一)
- php中序列化与反序列化
- 流-输入输出流
- xhEditor用法
- 总结
- swustoj dearway's problem(0240)
- Linux ext2, ext3, ext4 文件系统解读[3]
- JDBC的使用(mysql)
- spring源码-4-applicationContext(环境上下文)
- linux下valgrind内存泄露检查
- Ubuntu16.04使用小心得
- JS手撸数据结构系列(二) —— 树的遍历
- 【脚本语言系列】关于Python游戏工具Pygame,你需要知道的事
- css笔记1