Big Number

Problem 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

 
 
2 10 20

Sample Output

 
 
7 19

求阶乘的位数:N!=N*(N-1)*(N-2)......1

 对两边取对数:lg(N!)=lg(N*(N-1)*(N-2)......1)

                                  =lg(N)+lg(N-1)+lg(N-2)+......+lg1

然后对对数求和向上取整就可以得到结果。

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
	    int n;
	    double sum=0.0;
		scanf("%d",&n);
	    for(int i=2;i<=n;i++)
		{
			sum+=log10(i);
		}	
		printf("%d\n",int(ceil(sum)));
		
	}
	
	
	return 0;
}

### 处理 BigNumber 数据类型的挑战 在 Kettle 中处理 `BigNumber` 类型时,主要面临精度丢失的风险以及性能上的考量。由于 Kettle 默认会尝试将数值转换成适合传输和计算的形式,对于非常大的数字或者高精度的小数来说,这可能会导致不期望的结果[^1]。 为了确保大数据量下的准确性并优化效率,建议采用如下策略: #### 设置合适的字段类型 当定义流中的字段用于接收或发送 `BigNumber` 值时,应将其设置为 **Number** 或者更具体地指定为带有适当长度和小数位数BigDecimal 类型。这样可以在最大程度上保留原始数据的精确度。 ```properties Type=BigDecimal Precision=38 Scale=10 ``` #### 调整组件参数 某些特定的操作步骤可能会影响 `BigNumber` 的表现形式及其内部表示方式。例如,“计算器”插件允许用户自定义运算逻辑的同时也提供了选项来控制输出结果的数据格式;此时应当谨慎选择以防止不必要的舍入误差发生。 另外,在涉及到外部系统的交互过程中(比如通过 JDBC 连接器访问关系型数据库),务必确认目标端口能够接受来自 Kettle 发送过来的大数值,并且双方之间关于数值范围及显示格式达成一致理解。 #### 使用脚本解决复杂情况 如果内置功能无法满足需,则可以通过编写 JavaScript/Java Scriptlet 来实现更加灵活的数据变换过程。这类方法特别适用于那些需要特殊业务规则才能完成正确映射的情形下。 ```javascript // 示例:JavaScript 代码片段 var bigDecimalValue = row.big_number_field; // 获取输入列 if (bigDecimalValue != null && typeof(bigDecimalValue) === 'number') { var result = new java.math.BigDecimal(String(bigDecimalValue)); } else { throw "Invalid value encountered!"; } row.output_bigdecimal = result; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值