Digits of Factorial LightOJ - 1045
题目就不再发了,大致意思就是给你一个十进制数n,算出阶乘后转换成K进制的数,你来算一下它的位数。
坑点在哪呢,就是这个数可能算阶乘的时候没放弄了,比如1000000,做过最多单算阶乘的题也就是让你算到10000,所以这个如果按正常步骤来写肯定不行啦。
本题主要运用两个定理:
1丶 十进制位数就是 (int)log10(n),比如,1234,就是4,55555位数就是5。
对应K进制位数就是logk(n),但是math.h或者库函数里边log函数的底数只有固定的几个能直接用的,所以需要用到换底公式啦
2丶:loga(n)=logm(n)/logm(a)=ln(n)/ln(a);
3丶:核心思想 要求K进制位数:logk(n!)=ln(n!)/lnk + 1={ln(1)+ln(2)+ln(3)+...+ln(n)}/lnk + 1;
AC代码如下:大家看的时候可以自己再理解理解看看有没有更好的方法来解这道题啦,我这水平也有限,代码可能还不够完善呢。
#include<stdio.h>
#include<math.h>
#include<string.h>
#define ll long long
double aa[];
int main()
{ int t,c,m,n,i;
double ww;
scanf("%d",&t);
memset(aa,,sizeof(aa));
for(i=;i<=;i++)
aa[i]+=aa[i-]+log(i);//打个表来存一下前1000000个数的log(阶乘),会节省很多时间的
for(int i=;i<=t;i++)
{
scanf("%d%d",&m,&n);
if(m==)
printf("Case %d: 1\n",i);
else
{
ww=aa[m];//此处两行就是上边我介绍的核心思想了
ww=ww/log(n)+;//至于为什么+1,自己再想想啦
printf("Case %d: %d\n",i,(int)ww);
}
}
return ;
}
Digits of Factorial LightOJ - 1045的更多相关文章
- Digits of Factorial LightOJ - 1045(数学题?)
原文地址: https://blog.csdn.net/fenghoumilin/article/details/52293910 题意:求 n 的阶乘在 base 进制下的位数,这里有一个简单的方法 ...
- light oj 1045 - Digits of Factorial K进制下N!的位数
1045 - Digits of Factorial Factorial of an integer is defined by the following function f(0) = 1 f(n ...
- LightOJ Beginners Problems 部分题解
相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...
- 专题[vjudge] - 数论0.1
专题[vjudge] - 数论0.1 web-address : https://cn.vjudge.net/contest/176171 A - Mathematically Hard 题意就是定义 ...
- LOJ N!在不同进制的位数
lightoj1045 - Digits of Factorial (N!不同进制的位数) 对于一个B进制的数,只需要对其取以B的对数就可以得到他在B进制情况下的位数(取了对数之后可能为小数,所以还需 ...
- Problem 34
Problem 34 https://projecteuler.net/problem=34 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 1 ...
- LeetCode172 Factorial Trailing Zeroes. LeetCode258 Add Digits. LeetCode268 Missing Number
数学题 172. Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. N ...
- Intelligent Factorial Factorization LightOJ - 1035(水题)
就是暴力嘛...很水的一个题... 不好意思交都... #include <iostream> #include <cstdio> #include <sstream&g ...
- CodeForces 515C. Drazil and Factorial
C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- MyEclipse 10.7(版本:eclipse 3.7.x-Indigo系列)安装PyDev 4.5.4插件
解压安装路径结构如截图所示: 安装后重启:
- pyqt5 点开小窗口
# -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * class Fi ...
- php 通过array_merge()和array+array合并数组的区别和效率比较
众所周知合并两个数组可以使用array_merge(),这是php提供的一个函数.另外还可以通过 array 的方式来合并数组,这两种直接有什么区别,哪一个的效率更高呢? array_merge() ...
- P3203 [HNOI2010]弹飞绵羊(LCT)
P3203 [HNOI2010]弹飞绵羊 LCT板子 用一个$p[i]$数组维护每个点指向的下个点. 每次修改时cut*1+link*1就解决了 被弹出界时新设一个点,权为0,作为终点表示出界点.其他 ...
- P1357 花园
洛咕原题 题解 状压dp+矩乘 首先看到题目说M<=5,这么小的数据明显可以用状压保存相邻状态,于是可以得到一个80分的dp: 先筛出所有可用的状态,然后建立一个矩阵保存可转移的状态,再然后把每 ...
- centos6下jbd2进程占用大量IO处理
刚在尝试重现一个bug时,好像在killed mysql一段时间之后,io一直很高,如下: 12:40:01 PM CPU %user %nice %system %iowait %steal %id ...
- 【题解】Luogu P1533 可怜的狗狗
原题传送门 莫队介绍,Splay介绍 离线的题目,莫队是不错的解决方法 先把询问排一下序 剩下就套一个莫队的板子 每来一只狗就把漂亮值插入平衡树 每去掉一只狗就把漂亮值从平衡树中删掉 每次查询查平衡树 ...
- 【题解】Luogu P2073 送花
原题传送门 这题需要用到Splay 我们用一棵splay维护金钱 考虑c<=1000000 我们珂以把每种价格现在对应的美丽值存在一个a数组中 这样讲有珂能不太清楚qaq,还是对着操作一个一个讲 ...
- python3 logging模块
很多程序都有记录日志的需求,并且日志包含的信息有正常的程序访问日志还可能有错误,警告等信息输出,python的logging模块提供了标准的日志接口,可以通过它存储各种格式的日志,日志级别等级:cri ...
- 如何写好接口(php写app移动端接口示例)
原文链接:https://blog.csdn.net/xwh670570759/article/details/52130585?utm_source=blogxgwz0