2018年全国多校算法寒假训练营练习比赛(第三场)不凡的夫夫(斯特林公式)

xiaoxiao2021-02-28  20

链接: https://www.nowcoder.net/acm/contest/75/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld

题目描述

夫夫有一天对一个数有多少位数感兴趣,但是他又不想跟凡夫俗子一样, 所以他想知道给一个整数n,求n!的在8进制下的位数是多少位。

输入描述:

第一行是一个整数t(0<t<=1000000)(表示t组数据) 接下来t行,每一行有一个整数n(0<=n<=10000000)

输出描述:

输出n!在8进制下的位数。

示例1

输入

3 4 2 5

输出

2 1 3

用斯特林公式

n!的位数为:

本题程序

#include<cstdio> #include<cstring> #include<iostream> #include<cmath> using namespace std; #define PI 3.1415926535898 #define ll long long int main() { int T; ll n , ans; scanf("%d", &T); while(T--) { scanf("%lld", &n); if(n == 0) { printf("1\n"); continue; } ans = (int)((0.5*log(2*PI*n) + n*log(n) - n) / log(8)); printf("%lld\n",ans+1); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-2400115.html

最新回复(0)