LightOJ 1045 - Digits of Factorial 简单数论
2016-11-24 19:16
513 查看
题目:
http://www.lightoj.com/volume_showproblem.php?problem=1045题意:
给定两个数n m,求n!化为m进制后有多少位数字思路:
log10(n!) = log10(n) + log10(n-1) +…+ log10(1),化为m进制的话,则是logm(n!) = logm(n) + logm(n-1) +…+ logm(1),又有换底公式logm(n!) = log10(n!) / log10(m),可以先把log10(n!)打表出来,然后直接除以log10(m)就好了。没有预先打表,耿直的TLE了#include <bits/stdc++.h> using namespace std; const int N = 1000010; double arr ; int cas = 0; int main() { arr[0] = 0.0; for(int i = 1; i <= 1000000; i++) arr[i] = arr[i-1] + log10(i); int t, n, m; scanf("%d", &t); while(t--) { scanf("%d%d", &n, &m); double res = arr / log10(m); printf("Case %d: %d\n", ++cas, int(res) + 1); } return 0; }
相关文章推荐
- 【LightOJ】1045 - Digits of Factorial(数论)
- Lightoj1045 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】
- 【Ligth-oj】-1045 - Digits of Factorial(数论,log,好)
- LightOJ 1045 I - Digits of Factorial
- LightOJ 1045 Digits of Factorial
- LightOJ 1045 Digits of Factorial(大数进制)
- lightoj1045 - Digits of Factorial
- Light-oj-1045 lightoj1045 - Digits of Factorial (N!不同进制的位数)
- LightOJ 1045 Digits of Factorial
- LightOJ1045 Digits of Factorial 求n的阶乘在k进制下的位数
- lightoj 1045 - Digits of Factorial 【数学】
- lightoj 1045 - Digits of Factorial
- LightOJ 1045 Digits of Factorial
- LightOJ 1045 Digits of Factorial【进制问题】