A-不凡的夫夫——2018年全国多校算法寒假训练营练习比赛(第三场)

链接:https://www.nowcoder.net/acm/contest/75/A
来源:牛客网

题目描述
夫夫有一天对一个数有多少位数感兴趣,但是他又不想跟凡夫俗子一样,
所以他想知道给一个整数n,求n!的在8进制下的位数是多少位。
输入描述:
第一行是一个整数t(0

#include<cstdio>
#include<cmath>
#define pi acos(-1.0)
int main()
{
    double ans;
    int t;
    double temp = log(8),e=exp(1);
    scanf("%d", &t);
    while (t--)
    {
        int n;
        scanf("%d", &n);
        ans = ((log(2 * n*pi) / 2) + n*(log(n / e))) / temp + 1;
        if (n == 0 || n == 1)printf("1\n");
        else printf("%.0lf\n", floor(ans));
    }
}

猜你喜欢

转载自blog.csdn.net/q435201823/article/details/79257313