hdoj-1018-Big Number

来源:互联网 发布:北邮网络教育登录系统 编辑:程序博客网 时间:2024/06/05 00:44

Description

In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.
 

Input

Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤ 107 on each line.
 

Output

The output contains the number of digits in the factorial of the integers appearing in the input.
 

Sample Input

21020
 

Sample Output

719
#include<stdio.h>#include<math.h>#define pi 3.1415926int main(){    int t,n,x;    double a;    scanf("%d",&t);    while(t--)    {        scanf("%d",&n);        a=(n*log(n)-n+0.5*log(2*pi*n))/log(10);        x=int(a)+1;        printf("%d\n",x);    }    return 0;}


求N!的位数


这道题其实知道公式很好做,我记得有个和lg有关的公式,这道题其实我想了半天,最后是学长告诉我用斯特林公式算的,不过斯特林公式好像是个近似

0 0
原创粉丝点击