light oj 1045 - Digits of Factorial K进制下N!的位数
Factorial of an integer is defined by the following function
f(0) = 1
f(n) = f(n - 1) * n, if(n > 0)
So, factorial of 5 is 120. But in different bases, the factorial may be different. For example, factorial of 5 in base 8 is 170.
In this problem, you have to find the number of digit(s) of the factorial of an integer in a certain base.
Input
Input starts with an integer T (≤ 50000), denoting the number of test cases.
Each case begins with two integers n (0 ≤ n ≤ 106) and base (2 ≤ base ≤ 1000). Both of these integers will be given in decimal.
Output
For each case of input you have to print the case number and the digit(s) of factorial n in the given base.
Sample Input |
Output for Sample Input |
|
5 5 10 8 10 22 3 1000000 2 0 100 |
Case 1: 3 Case 2: 5 Case 3: 45 Case 4: 18488885 Case 5: 1 |
分析:换底公式log a b = log c b / log c a; 所以logk(fn) = log10(fn)/ log10k; logq0(fn) = log10(N) = log10(1 * 2 *...*n) = log10(1) + 1og10(2) .....+ 1og10(n)
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define N 1000009
using namespace std;
double a[N];
void init()
{
a[0] = log10(1);
for(int i = 1; i <= N; i++)
a[i] = a[i-1] + log10(i*1.0);
}
int main(void)
{
int T, cas;
int n, k;
init();
scanf("%d", &T);
cas = 0;
while(T--)
{
cas++;
scanf("%d%d", &n, &k);
if(n == 0)
printf("Case %d: 1\n", cas);
else
{
double ans = ceil(a[n]/log10(k*1.0));
printf("Case %d: %d\n", cas, (int)ans);
}
}
light oj 1045 - Digits of Factorial K进制下N!的位数的更多相关文章
- n!在k进制下的后缀0
问n! 转化成k进制后的位数和尾数的0的个数.[UVA 10061 How many zeros and how many digits?] Given a decimal integer numbe ...
- 陕西师范大学第七届程序设计竞赛网络同步赛 F WWX的礼物【数学/k进制下x^n的位数/log】
链接:https://www.nowcoder.com/acm/contest/121/F来源:牛客网 题目描述 WWX的女朋友送给了他一个礼物,可是礼物却被一把K进制密码锁锁住了.在礼物盒上还有一张 ...
- bzoj 3000 Big Number 估算n!在k进制下的位数 斯特林公式
题目大意 求n!在k进制下的位数 2≤N≤2^31, 2≤K≤200 分析 作为数学没学好的傻嗨,我们先回顾一下log函数 \(\log_a(b)=\frac 1 {log_b(a)}\) \(\lo ...
- 51 Nod 1116 K进制下的大数
1116 K进制下的大数 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 有一个字符串S,记录了一个大数,但不知这个大数是多少进制的,只知道这个数 ...
- 求x!在k进制下后缀零的个数(洛谷月赛T1)
求x!在k进制下后缀和的个数 20分: 求十进制下的x!后缀和的个数 40分: 高精求阶乘,直接模拟过程 (我不管反正我不打,本蒟蒻最讨厌高精了) 60分 利用一个定理(网上有求x!在 ...
- [51nod1116]K进制下的大数
解题关键:$A\% (k - 1) = (A[0] + A[1]*k + A[2]*{k^2} + ...A[n]*{k^n})\% (k - 1) = (A[0] + A[1] + ...A[n]) ...
- 数位DP 求K进制下0~N的每个数每位上出现的数的总和
好久没写博客了,因为感觉时间比较紧,另一方面没有心思,做的题目比较浅也是另一方面. 热身赛第二场被血虐了好不好,于是决定看看数位DP吧. 进入正题: 如题是一道经(简)典(单)的数位dp. 第一步,对 ...
- 51nod 1116 K进制下的大数
你万万想不到,Long Long 就能存下的数据 #include <iostream> #include <cstdio> #include <cstdlib> ...
- 51nod 1116 K进制下的大数 (暴力枚举)
题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...
随机推荐
- 测试必备之Java知识(四)—— 线程相关
线程相关 Java多线程实现方式 继承Thread,实现Runnable接口,实现Callable接口(能抛异常且有返回值,不常用) 为什么有了继承Thread方式还要有Runnable接口方式 实现 ...
- Qt Installer Framework翻译(3-3)
移除组件 下图说明了删除所有或某些已安装组件的默认工作流程: 本节使用在macOS上运行的Qt 5维护工具为例,来演示用户如何删除所有或部分选定组件. 移除所有组件 用户启动维护工具时,将打开&quo ...
- .Net Core2.*学习手册
1.net core 基础知识解析(创建一个.net core网站)(视频录制) 1.1 Startup解析(没写) 1.2 目录结构分析(没写) 1.3 使用静态文件(没写) 1.4 Control ...
- [bzoj4417] [洛谷P3990] [Shoi2013] 超级跳马
Description 现有一个n行m列的棋盘,一只马欲从棋盘的左上角跳到右下角.每一步它向右跳奇数列,且跳到本行或相邻行.跳越期间,马不能离开棋盘.例如,当n = 3, m = 10时,下图是一种可 ...
- 利用Python进行博客图片压缩
自己写博客的时候常常要插入一些手机拍的照片,都是几M的大小,每张手动压缩太费事了,于是根据自己博客的排版特点用Python写了一个简单的图片压缩脚本,功能是将博客图片生成缩略图,横屏的图片压缩为宽度最 ...
- HTML5的web 存储localStorage、sessionStorage
说明 随着互联网的快速发展,基于网页的应用越来越普遍,同时也变的越来越复杂,为了满足各种各样的需求,会经常性在本地存储大量的数据,HTML5规范提出了相关解决方案.我们可以使用localStorage ...
- C#系列之基础知识点(一)
知识点一:VS启动方法 第一种:双击图标 第二种:window+R——调出cmd,输入devenu properties 属性的意思 知识点二:后缀名解释 .sln 解决方案文件:包含整个解决方案 ...
- CSS 故障艺术
本文的主题是 Glitch Art,故障艺术. 什么是故障艺术?我们熟知的抖音的 LOGO 正是故障艺术其中一种表现形式.它有一种魔幻的感觉,看起来具有闪烁.震动的效果,很吸引人眼球. 故障艺术它模拟 ...
- c++中静态成员函数
静态成员函数 静态成函数和静态成员数据相同,他们都属于某一个类的静态成员而不是某一个对象的成员. 静态数据成员的使用方法和注意事项 1.静态数据成员在定义或说明时前面加上关键字static 2.初始化 ...
- LinearLayout里面的空间居中对齐
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...