描述
夫夫有一天对一个数有多少位数感兴趣,但是他又不想跟凡夫俗子一样,
所以他想知道给一个整数n,求n!的在8进制下的位数是多少位。
输入
第一行是一个整数t((0,1000000]),接下来t行,每行一个整数n(【0,10000000】);
输出
输出n!在8进制下的位数。
样例输入
3
4
2
5
样例输出
2
1
3
n!的位数res为:
该公式所求的是在10进制下的阶乘的位数,所以要将lg(x)改成log8(x)才行,换底公式即可。
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<malloc.h>
#include<math.h>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<vector>
#define inf 0x3f3f3f3f
#define N 1000000+10
#define LL long long
char num[100000],sum[100000];
using namespace std;
const double e = 2.71828182845;
const double pi = 3.1415926;
const double log8_e = log10(e)/log10(8.0);
#define log8_2_pi(x) (log10(2.0*pi*x)/log10(8.0))/2.0
#define log8(x) log10(x)/log10(8.0)
int main(void)
{
int t,s;
double a;
scanf("%d",&t);
while (t--)
{
int v;
scanf("%d", &v);
if (1 == v||v==0) {printf("1\n"); continue;}
a = v;
s = (int)(log8_2_pi(a) + a*log8(a) - a * log8_e)+1;
printf("%d\n",s);
}
return 0;
}
链接:https://www.nowcoder.net/acm/contest/75/A
来源:牛客网