lightOJ 1045 Digits of Factorial (数位计数)
2017-01-15 16:40
411 查看
题目分析
首先我们知道log(a∗b)=log(a)+log(b),那么很明显如果是在k进制下n的阶乘,那么位数为lognk!+1=log1k+log2k+log3k+......+lognk+1,那么结果已经很明显了。我们可以先处理处10进制下的n个阶乘所得的数,然后如果是其他阶乘直接乘以log(10)/log(b)即可。#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 1e6+100; double ans[maxn]; //计算10进制所得的位数 void init(){ ans[0] = 0; for(int i = 1; i < maxn; i++) ans[i] = log10(i) + ans[i-1]; } int main(){ init(); int T; scanf("%d", &T); for(int kase = 1; kase <= T; kase++){ int n, b; scanf("%d%d", &n, &b); double temp = log(10)/log(b)*ans ; printf("Case %d: %d\n", kase, (int)temp+1); } return 0; }
相关文章推荐
- lightoj 1045 - Digits of Factorial 【数学】
- LightOJ 1045 Digits of Factorial
- Lightoj1045 Digits of Factorial(数论)
- LIGHTOJ 1045 - Digits of Factorial 【阶乘取对数】
- Light-oj-1045 lightoj1045 - Digits of Factorial (N!不同进制的位数)
- 【LightOJ 1045 Digits of Factorial】
- LightOJ 1045 Digits of Factorial(大数进制)
- LightOJ 1045 I - Digits of Factorial
- lightoj1045 - Digits of Factorial
- 【LightOJ】1045 - Digits of Factorial(数论)
- LightOJ 1045 Digits of Factorial【进制问题】
- lightoj 1045 - Digits of Factorial
- lightoj 1045 - Digits of Factorial (数学-log运用--阶乘进制位数)
- LightOJ 1045 Digits of Factorial
- lightoj1045 - Digits of Factorial(数论)
- lightoj 1045 - Digits of Factorial 取对数
- LightOJ 1045 Digits of Factorial
- lightoj1045 - Digits of Factorial
- LightOJ1045 Digits of Factorial 求n的阶乘在k进制下的位数
- LightOJ 1045 - Digits of Factorial 简单数论