-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1045 - Digits of Factorial.cpp
77 lines (73 loc) · 1.37 KB
/
1045 - Digits of Factorial.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Author: Ashraful Islam Rafi
* University: Leading University,Sylhet
* url: http://www.lightoj.com/volume_showproblem.php?problem=1045
* problem id: 1045- Digits of Factorial
* complexity: Beginners Problems, Number Theory.
* site: Lightoj.com
**/
#include"map"
#include"set"
#include"queue"
#include"cmath"
#include"stack"
#include"ctype.h"
#include"cstdio"
#include"vector"
#include"cstdio"
#include"cstring"
#include"cstdlib"
#include"string.h"
#include"iostream"
#include"algorithm"
using namespace std;
#define cs "Case "<<++casee<<": "
#define csE "Case "<<++casee<<":\n"
#define Inf 1000000000
#define NN 5000010
#define MST(a, tf) memset(a, tf, sizeof (a))
int i,j,p,c,noz,k;int N,B;
double cache[1000010];
double Digit_of_factorial(int n)
{
double ans=cache[n];
ans/=log(B);
ans+=1.0;
ans=floor(ans);
return ans;
}
int main()
{
int t;scanf("%d",&t);
MST(cache,0);
int casee=0;
double ans=0;
for (i=1;i<=1000003;i++)
{
ans+=log(i); ///cout<<ans;cout<<endl;
cache[i]=ans;
}
while(t--)
{
double answer=0;
scanf("%d%d",&N,&B);
answer=Digit_of_factorial(N); //answer=floor(answer);
printf("Case %d: %.0lf\n",++casee,answer);
}
}
///--test case--///
/**
10
5 10
8 10
22 3
1000000 2
0 100
390338 185
Case 1: 3
Case 2: 5
Case 3: 45
Case 4: 18488885
Case 5: 1
Case 6: 887906
*/