ACM之北大——1423_Big Number

Big Number
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 26865 Accepted: 8581

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 <= m <= 10^7 on each line.

Output

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

Sample Input

2
10
20

Sample Output

7
19
java解法:
/**
 *
解释:
	3、2、1、0的阶乘都是小于10的数,也就是1位数,所以,可以单独列出来,不多说;
	自此,大于3的正整数,通过阶乘公式  n!= 1*2*3*...*(n-1)*n 求得,但是,此题的
	目的并不在于此,而是求n的阶乘的位数。
	而斯特林公式就是最好的选择,下面是百度百科的公式链接地址,不多说;
	http://baike.baidu.com/link?url=G6h67Aybh9i_jGt-GcLQcM2OourEQFcN_nhj3QmvvkYdHfIO4WLZlGgXR3Zx1gUKF-J7nkEFt-jfEOHV36T_aa
	求阶乘结果的位数可用由 10^(x-1)≤n!≤10^x,再取对数获得(x表示位数,高中数学log10求解)。
 */
import java.util.*;


public class Big_Number{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);


		int n = sc.nextInt();
		while (n --> 0) {
			int n1 = sc.nextInt();
			if (n1 <= 3)
				System.out.println(1);
			else {
				double result = 0.5 * Math.log10(2 * n1 * Math.PI) + n1
						* Math.log10(n1 / Math.E) + 1;
				System.out.println((int) (result));
			}		
		}
	}


}

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值