zoukankan      html  css  js  c++  java
  • 51 nod 1058 N的阶乘的长度

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

    n的长度len(n)=log10(n)+1,直接去掉小数点后的部分
    所以len(n!)=log10(1*2*……*n)=log10(1)+log10(2)+……+log10(n)
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int main()
    {
        int n;
        double ans=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
         ans+=log10(i*1.0);
        int k=int(ans);
        printf("%d",k+1);
    }

    -----------------------------------------------------------------------------

    #include<cstdio>
    using namespace std;
    int main()
    {
        double a=5.634;
        printf("%.0lf
    ",a);//6
        printf("%.lf
    ",a);//6
        printf("%g
    ",a);//5.634
        
        int b=(int)a;//a仍是原类型 
        printf("%d
    ",b);//5    直接去掉小数点 
        
        printf("%.0lf
    ",a);//6
        printf("%.lf
    ",a);//6
        printf("%g
    ",a);//5.634
    }
  • 相关阅读:
    python学习之路-day3
    python学习之路-day2
    python学习之路-day1
    Hystrix断路器
    jmater的使用
    记录1
    springcloud-Gateway
    Quartz框架
    红黑树的左旋和右旋
    异步回调CompletableFuture
  • 原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/6631247.html
Copyright © 2011-2022 走看看