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 ≤ 10[sup]7[/sup] on each line.
Output The output contains the number of digits in the factorial of the integers appearing in the input.
Sample Input2
10
20
Sample Output7
19
#include<stdio.h>
#include<math.h>
int main()
{
int n,a,s=1,i,j;
double m=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
s=1;
m=0;
scanf("%d",&a);
for(j=1;j<=a;j++)
{
m=m+log10(j);
}
printf("%d\n",int(m+1));
}
}
The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.
For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.
Input The input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.
Output For each integer in the input, output its digital root on a separate line of the output.
Sample Input24
39
0
Sample Output6
3
#include<stdio.h>
#include<string.h>
int main()
{
int n,i;
char c[9999];
int sum,m;
while(scanf("%s",c)&&c[0]!='0')
{
sum=0;
for( i=0;i<strlen(c);i++)
sum+=c[i]-'0';
while(sum>=10)
{
m=sum;
sum=0;
while(m>0)
{
sum+=m%10;
m/=10;
}
}
printf("%d\n",sum);
}
return 0;
}