好吧这题很水。。。可是我没想到正解。。。


题意:求n!有多少位。

正解:斯特林公式。

直接放代码。。。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define R register int
static char B[<<],*S=B,*D=B;
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin))?EOF:*S++)
const int N=;
const long double PI=3.141592653589793238463,e=2.7182818284590452354;
using namespace std;
inline int g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
} double d;
inline int calc(int n) {
return log10(*PI*n)/2.0+n*log10(n/e);
}
signed main() {
R t=g(); while(t--) {
R n=g(); printf("%d\n",calc(n)+);
}
}

然后是暴力:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define R register int
static char B[<<],*S=B,*D=B;
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin))?EOF:*S++)
const int N=;
const long double PI=3.141592653589793238463,e=2.7182818284590452354;
using namespace std;
inline int g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
} double d; int c[N];
signed main() {
for(R i=;i<=N;++i) d+=log10(i),c[i]=(int)d+;
R t=g(); while(t--) {
R n=g(); printf("%d\n",c[n]);
}
}

2019.06.02怕不是失了智qwq

POJ1423 Big Number 暴力or斯特林公式??的更多相关文章

  1. XTU OJ 1210 Happy Number (暴力+打表)

    Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...

  2. hdu 3711 Binary Number(暴力 模拟)

    Problem Description For non-negative integers x and y, f(x, y) , )=,f(, )=, f(, )=. Now given sets o ...

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

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

  4. POJ1423 - Big Number(Stirling公式)

    题目大意 求N!有多少位 题解 用公式直接秒杀... 代码: #include<iostream> #include<cmath> using namespace std; # ...

  5. NBUT 1223 Friends number 2010辽宁省赛

    Time limit  1000 ms Memory limit   131072 kB Paula and Tai are couple. There are many stories betwee ...

  6. LeetCode 287. Find the Duplicate Number (python 判断环,时间复杂度O(n))

    LeetCode 287. Find the Duplicate Number 暴力解法 时间 O(nlog(n)),空间O(n),按题目中Note"只用O(1)的空间",照理是过 ...

  7. 《剑指offer》-青蛙跳台阶II

    一只青蛙一次可以跳上1级台阶,也可以跳上2级--它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 其实题目很水...就是一个等比数列通项公式嘛 f(0)=1 f(1)=1 f(n)=f( ...

  8. [Codeforces]Codeforces Round #460 (Div. 2)

    Supermarket 找最便宜的就行 Solution Perfect Number 暴力做 Solution Seat Arrangement 注意当k=1时,横着和竖着是同一种方案 Soluti ...

  9. HDU 1394 Minimum Inversion Number(最小逆序数/暴力 线段树 树状数组 归并排序)

    题目链接: 传送门 Minimum Inversion Number Time Limit: 1000MS     Memory Limit: 32768 K Description The inve ...

随机推荐

  1. IDEA插件之CheckStyle

    1.是个啥? CheckStyle是一个检测代码格式是否满足规范的工具,其中用得比较多的是Google规范和Sun规范 2.下载安装插件 File -> Settings -> Plugi ...

  2. C++ STL Vector学习 (待续)

    头文件:<vector> 初始化 vector<Elementtype> vec(); /*Elementtype是数据类型,10代表长单为10*/ vector<Ele ...

  3. nginx访问量统计 日常分析

    nginx访问量统计 0.查询某个时间段的日志 cat appapi.dayutang.cn.access.log |grep 'POST'|grep '2019:10' > 20191059. ...

  4. operator模块和functools模块

    operator模块 在函数式编程中,经常需要把算术运算符当作函数使用.例如,不使用 递归计算阶乘.求和可以使用 sum 函数,但是求积则没有这样的函数. 我们可以使用 reduce 函数(5.2.1 ...

  5. 9.ssh登录慢

    修改方式:使用root权限修改ssh的配置文件,vim /etc/ssh/sshd_config增加一行记录:UseDNS no修改GSSAPIAuthentication参数为 no,默认是yesP ...

  6. centos中拉取postgre

    新搭建好的linux服务器环境,docker也配置好了. 第一步,下载postgre docker pull postgres:11 这里的版本号自己按照自己的需要来获取. 然而实际上没那么顺利,直接 ...

  7. 【php设计模式】观察者模式

    当对象间存在一对多关系时,则使用观察者模式.比如,当一个对象被修改时,则会自动通知它的依赖对象.观察者模式属于行为型模式. <?php class Subject{ private $obser ...

  8. 12.SpringMVC核心技术-请求转发和重定向

    默认情况下,跳转到指定的View,使用的是请求转发.也可以显示的进行指出 此时,需在setViewName()  指定的视图前添加 forword: , 且此时的视图不会再与视图解析器中的前缀和后缀进 ...

  9. python生成式:列表、字典、集合

    python的3类生成式: 列表生成式 字典生成式 集合生成式 1.python列表生成式 my_data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] print(&quo ...

  10. Error:Execution failed for task ':app:compileDebugJavaWithJavac'

    百度一下呗 查找了各种解决方案,都不对症. 最后发现,造成这种异常的原因有很多.具体的还是要去终端编译,查看到底是什么地方出错了,然后具体问题具体分析. 终端进入项目的根目录,然后输入命令 ./gra ...