新手求解 多次循環輸入
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.
这个题目中,会给你一个数字,要求算出这个数字的阶乘。阶乘的定义,比如说下面例子里出现的10. 把1 2 3 4 5 6 7 8 9 10 这10个数字相乘,得出3628800。3628800是个7位数。
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 ≤ 10^7 on each line.
输入的东西是由很多行整数组成的。第一行包含一个整数n,n就代表我们需要完成的测试的数量,第一行下面将跟着n行,一行一个整数,这个整数要大于小于1,小于等于10的七次方
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
#include"stdio.h"#include"math.h"int factorial(int n){long a[10000];char b[n];int i,j,l,c,m=0,w; a[0]=1; for(i=1;i<=n;i++) { c=0; for(j=0;j<=m;j++) { a[j]=a[j]*i+c; c=a[j]/10000; a[j]=a[j]%10000; } if(c>0) { m++; a[m]=c; } } w=m*4+log10(a[m])+1;printf("%d\n",w);return w;}main (int x){ long z[10^7],o; scanf("%d",&x); for(o=0;o<x;o++) scanf("%d",&z[o]); for(o=0;o<x;o++) { if(x<=10^7&&x>=1) factorial(z[o]); else printf("error!\n"); } }