LightOJ 1045 Digits of Factorial
2012-12-02 20:25
459 查看
题目链接 http://lightoj.com/volume_showproblem.php?problem=1045
题意:计算N!在K进制下的位数,即计算log(1)+log(2)+...+log(N)其中log的底数都是K
思路:首先利用log(xy)=log(x)+log(y)可以求出log(n!)..然后换底公式求出log(b,n!)...然后加1即可。
询问次数很多,每次都重新算TLE的。
所以data[i]=1..i的log(i)之和,也就是前缀和的优化.然后O(1)回答每次询问。
题意:计算N!在K进制下的位数,即计算log(1)+log(2)+...+log(N)其中log的底数都是K
思路:首先利用log(xy)=log(x)+log(y)可以求出log(n!)..然后换底公式求出log(b,n!)...然后加1即可。
询问次数很多,每次都重新算TLE的。
所以data[i]=1..i的log(i)之和,也就是前缀和的优化.然后O(1)回答每次询问。
#include <stdio.h> #include <math.h> double data[1000010]; int main() { int T,n,b; scanf("%d",&T); for (int i=1;i<1000005;i++) data[i]=log(double(i))+data[i-1]; for (int cas=1;cas<=T;cas++) { scanf("%d%d",&n,&b); printf("Case %d: %d\n",cas,int(data /(data[b]-data[b-1]))+1); } return 0; }
相关文章推荐
- LightOJ1045 Digits of Factorial 求n的阶乘在k进制下的位数
- LightOJ 1045 Digits of Factorial
- LightOJ 1045 I - Digits of Factorial
- LightOJ - 1045 Digits of Factorial
- lightoj1045 - 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 【阶乘取对数】
- Light-oj-1045 lightoj1045 - Digits of Factorial (N!不同进制的位数)
- LightOJ 1045 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 (数位计数)
- lightoj 1045 - Digits of Factorial 取对数
- 【LightOJ】1045 - Digits of Factorial(数论)