LightOJ 1045 Digits of Factorial
来源:互联网 发布:php程序员如何提高水平 编辑:程序博客网 时间:2024/05/22 01:27
Problem:acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=26765
分析:在base进制下,pow ( base , x ) 表示最小的 x+1 位数,pow ( base , x ) -1 表示最大的 x 位数
所以base进制下 x 位数的范围是 [ pow ( base , x-1 ) , pow ( base , x ) ),前闭后开的区间
10进制为例,10^2 = 100是最小的3位数,10^3 = 1000是最小的4位数,10^3 -1 = 999是最大的3位数
所以题目是要求出这个 x,使得 pow ( base , x-1 ) <= n! < pow ( base , x ),即第一个使得 pow ( base , x ) > n! 的x
但是n 最大是1e6,不能真的求 n!,所以取对数,于是变成:x * log ( base ) > log ( n! ) = log(1) + log(2) + … +log(n)
log (base) 除过去得出 x,要向上取整
要注意 n=0 的情况,答案是1
预处理一个装 log( i ) 前缀和的数组,不然会超时
Source code
#include <stdio.h>#include <math.h>#define SIZE 1000000double sum[SIZE+1];int main(){ int iTom,kase; for(sum[0]=0,kase=1;kase<=SIZE;kase++) sum[kase]=sum[kase-1]+log(kase); scanf("%d",&iTom); for(kase=1;kase<=iTom;kase++) { int n,base,out; double ans; scanf("%d%d",&n,&base); if(n<2) { printf("Case %d: 1\n",kase); continue; } out=ans=sum[n]/log(base); ans-=out; if(ans>0) out++; printf("Case %d: %d\n",kase,out); } return 0;}
0 0
- 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】
- LightOJ 1045 Digits of Factorial
- LightOJ 1045 Digits of Factorial
- lightoj 1045 - Digits of Factorial 取对数
- lightoj 1045 - Digits of Factorial 【数学】
- LightOJ 1045 I - Digits of Factorial
- 【LightOJ】1045 - Digits of Factorial(数论)
- LightOJ 1045 - Digits of Factorial 简单数论
- lightOJ 1045 Digits of Factorial (数位计数)
- lightoj 1045 Digits of Factorial (数学)
- Jan's LightOJ :: Problem 1045 - Digits of Factorial
- LIGHTOJ 1045 - Digits of Factorial 【阶乘取对数】
- LightOJ 1045 Digits of Factorial(大数进制)
- mysql 入门基础(1)—数据库定义
- JAVA 递归 汉诺塔+阶乘
- 【NOI题库 动态规划】
- 20 个常用的 CSS 技巧
- LA 4327 Parade (DP单调队列)
- LightOJ 1045 Digits of Factorial
- 关于android studio下的handler问题
- ES6学习笔记(五)--函数与对象
- 团体程序设计天梯赛-练习集 L3-003 社交集群 并查集 解题报告
- eclipse安装subclipse插件在win7中使用报错问题解决方案
- appledoc 使用方法
- SQL Server 2016新特性: Temporal table
- CSS3的nth-child() 和nth-of-type()选择器,表格奇偶行变色
- Java中的函数