SGU 154. Factorial
来源:互联网 发布:金川集团网络学校 编辑:程序博客网 时间:2024/05/29 16:12
154. Factorial
time limit per test: 0.5 sec.
memory limit per test: 4096 KB
memory limit per test: 4096 KB
input: standard input
output: standard output
output: standard output
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail.
Input
One number Q written in the input (0<=Q<=10^8).
Output
Write "No solution", if there is no such number N, and N otherwise.
Sample test(s)
Input
2
Output
10
题目大意:给出一个数n的阶乘n!的末尾0的个数,求n最小是多少,如果找不到输出No solution
思路分析:由于2和5乘积会出现0,所以可以二分一个范围,是否存在一个数末尾0的个数满足要求
#include<iostream>using namespace std;int cal(int n){ int res=0; while(n) { res+=n/5; n/=5; } return res;}int main(){ int q; while(cin>>q) { if(q==0) { cout<<1<<endl; continue; } int right=1000000003,left=1; int mid; while(left<right) { mid=(left+right)/2; if(cal(mid)<q) left=mid+1; else right=mid; } if(cal(left)==q) cout<<left<<endl; else cout<<"No solution"<<endl; }}
- SGU 154. Factorial
- SGU 154. Factorial
- sgu 154 Factorial
- SGU 154-Factorial
- SGU - 154 - Factorial (数论)
- SGU-154 Factorial (末尾0 & 三分)
- SGU 154 Factorial(数论+二分)
- Factorial!
- Factorial
- Factorial
- factorial
- Factorial
- Factorial
- Factorial
- Factorial
- Factorial
- Factorial
- Factorial
- 中国天气网API
- 经典字典树模板
- C++与QML的集成
- JAVA 正则表达式 (超详细)
- const int *p,int *const p区别
- SGU 154. Factorial
- SGU 102(欧拉函数)
- android 2.3.7 miui rom的修改
- 2013编程之美 初赛 传话游戏
- 第七届北京交通大学ACM程序设计竞赛网络预赛二
- 大数相加
- STL关联容器之Map
- 给大家共享好东西喽! 查找数据库中指定字符串,支持2005以上
- 初识递归