求n!在k进制下的位数,n<=1e18

斯特林公式:$n!\approx \sqrt{2\pi n}(\frac{n}{e})^n$

在n很大的时候有较好的精度保证。

$\log_{k}n!+1=\frac{1}{2}\frac{\ln(2\pi n)}{\ln k}+n\frac{\ln n-\ln e}{\ln k}+1$

n较小时直接暴力求解即可。

 #include<cmath>
#include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std; const double pi=acos(-.),e=exp(),eps=1e-;
int n,k; int main(){
while (~scanf("%d%d",&n,&k)){
if (n<=){
double ans=;
rep(i,,n) ans+=log(i); ans/=log(k);
printf("%d\n",(int)ceil(ans+eps));
}else printf("%lld\n",(long long)(0.5*log(*pi*n)/log(k)+n*(log(n)-log(e))/log(k)+));
}
return ;
}

[BZOJ3000]Big Number(斯特林公式)的更多相关文章

  1. bzoj3000 Big Number 数论,斯特林公式

    Description 给你两个整数N和K,要求你输出N!的K进制的位数. Input 有多组输入数据,每组输入数据各一行,每行两个数——N,K Output 每行一个数为输出结果 Sample In ...

  2. hdu1018 Big Number 斯特林公式 求N!的位数。

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. HDU-Big Number (斯特林公式)

    In many applications very large integers numbers are required. Some of these applications are using ...

  4. HDU 1018 Big Number 斯特林公式

    Big Number 题意:算n!的位数. 题解:对于一个数来算位数我们一般都是用while去进行计算,但是n!这个数太大了,我们做不到先算出来在去用while算位数. while(a){ cnt++ ...

  5. BZOJ3000 Big Number

    由Stirling公式: $$n! \approx \sqrt{2 \pi n} (\frac{n}{e})^n$$ 故:$$\begin{align} ans &= log_k n! + 1 ...

  6. [BZOJ3000] Big Number (Stirling公式)

    Description 给你两个整数N和K,要求你输出N!的K进制的位数. Input 有多组输入数据,每组输入数据各一行,每行两个数——N,K Output 每行一个数为输出结果. Sample I ...

  7. hdu--1018--Big Number(斯特林公式)

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. POJ 1423:Big Number 求N的阶乘的长度 斯特林公式

    Big Number Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27027   Accepted: 8626 Descr ...

  9. HDU 1018 Big Number【斯特林公式/log10 / N!】

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. bzoj 3126: [Usaco2013 Open]Photo——单调队列优化dp

    Description 给你一个n长度的数轴和m个区间,每个区间里有且仅有一个点,问能有多少个点 Input * Line 1: Two integers N and M. * Lines 2..M+ ...

  2. Linux while 和 read 的用法

    Reference: [ linux man doc ] [ CSDN roler_ ] [ Reads from the file descriptor] read 命令说明 SYNTAX : re ...

  3. centos6.5下安装svn并且实现多项目管理配置方案

    #安装SVN服务器 yum install subversion #在home下创建svn根目录 mkdir /home/svn #在 /home/svn下创建pro1 , pro2, pro3 三个 ...

  4. auto-keras 测试保存导入模型

    # coding:utf-8 import time import matplotlib.pyplot as plt from autokeras import ImageClassifier# 保存 ...

  5. fs.createReadStream(filepath).pipe(response);这句是什么意思?

    'use strict'; var fs = require('fs'), url = require('url'), path = require('path'), http = require(' ...

  6. python模块subprocess学习

    当我们想要调用系统命令,可以使用os,commands还有subprocess模块整理如下: os模块: 1. os.system 输出命令结果到屏幕.返回命令执行状态. >>> o ...

  7. css3_box-shadow使用记录

    1.box-shadow这个属性有6个参数可设置,使用的时候比较少用,每次使用的时候都会忘记,故写此文作记录. 样式: /*1.添加此属性添加阴影*/ box-shadow: 0 0 10px 10p ...

  8. Part2-HttpClient官方教程-Chapter4-HTTP 认证

    原文链接地址 HttpClient 提供对由 HTTP 标准规范定义的认证模式的完全支持.HttpClient 的认证框架可以扩展支持非标准的认证模式,比如 NTLM 和 SPNEGO. 4.1 用户 ...

  9. linux编程之消息队列

    消息队列是内核地址空间中的内部链表,通过linux内核在各个进程之间传递内容,消息顺序地发送到消息队列中,并且以几种不同的方式 从队列中获取,每个消息队列可以用IPC标识符唯一的进行标识,内核中的消息 ...

  10. 2012年Elsevier旗下Computer Science期刊最新SCI影响因子排名

    Latest Impact Factor figures from Elsevier's Computer Science Journals Medical Image Analysis Impact ...