首页 > 其他 > 详细

POJ 1423 Big Number

时间:2015-09-30 16:26:45      阅读:132      评论:0      收藏:0      [点我收藏+]

题意:求n阶乘的位数。

 

解法:斯特林公式,技术分享,然后取log10就是位数了,因为精度问题需要化简这个式子,特判1。

 

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
const double pi = acos(-1.0);
const double e = 2.718281828459;
int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int n;
        scanf("%d", &n);
        if(n == 1)
        {
            puts("1");
            continue;
        }
        printf("%d\n", (int)ceil(0.5 * log10(2.0 * pi * n) + log10((double)n) * n - log10(e) * n));
    }
    return 0;
}

  

POJ 1423 Big Number

原文:http://www.cnblogs.com/Apro/p/4849262.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!