码迷,mamicode.com
首页 > 其他好文 > 详细

51nod 1058 N的阶乘的长度 位数公式

时间:2017-11-12 16:33:31      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:思路   es2017   git   style   ios   names   技术分享   c++   .com   

1058 N的阶乘的长度
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注
输入N求N的阶乘的10进制表示的长度。例如6! = 720,长度为3。
Input
输入N(1 <= N <= 10^6)
Output
输出N的阶乘的长度
Input示例
6
Output示例
3
思路:
位数公式

技术分享

则有: 

技术分享

技术分享

技术分享

循环遍历即可

代码:

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main() {
 4     ios::sync_with_stdio(false);
 5     int N;
 6     cin>>N;
 7     double digit=0;
 8     for(int i=1;i<=N;++i) {
 9         digit+=log10(i*1.0);
10     }
11     cout<<(int)digit+1<<endl;
12     return 0;
13 }
View Code

 

51nod 1058 N的阶乘的长度 位数公式

标签:思路   es2017   git   style   ios   names   技术分享   c++   .com   

原文地址:http://www.cnblogs.com/lemonbiscuit/p/7821692.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!