-
Notifications
You must be signed in to change notification settings - Fork 3
/
lengfact.c
50 lines (43 loc) · 912 Bytes
/
lengfact.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<stdio.h>
#include<math.h>
/*
Very easy problem, just use stirling formula
with logarithm to calculate number of digits
Precompute all the constant values to get
the best result (of course)
*/
int main()
{
int test_cases=0,i;
double result,number,pi,e,A,B;
unsigned long long int resultInt;
int y;
pi=3.1415926535;
/*
e value is required to be of high precision
since it's log value gets multiplied by the
given number in the final answer
*/
e=2.71828182845904523536;
A=log10(2.0*pi);
A=A/2;
B=log10(e);
scanf("%d",&test_cases);
for(i=0;i<test_cases;i++)
{
scanf("%lf",&number);
if(number==1 || number == 0)
{
resultInt=1;
}
else
{
result=(number+0.5)*log10(number);
result=result+A-(number*B);
resultInt=(unsigned long long int)(result);
resultInt++;
}
printf("%lld\n",resultInt);
}
return 0;
}