Skip to content

Commit 1407645

Browse files
committed
light oj 1045 Number Theory
1 parent a8f3f60 commit 1407645

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

LightOj/1045-Digits of Factorial.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define flush cin.ignore(numeric_limits<streamsize>::max(),'\n')
5+
#define FASTERIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
6+
#define NL cout<<'\n';
7+
#define pi acos(-1.0) //3.1415926535897932384626
8+
#define pb push_back
9+
#define mk make_pair
10+
#define MaxN 10000008 //1e5
11+
#define EPS 1e-18
12+
#define dpoint(x) fixed<<setprecision(x)
13+
#define Fill(ar, weight) memset(ar, weight, sizeof(ar))
14+
typedef long long int ll;
15+
typedef double dl;
16+
typedef unsigned long long int ull;
17+
18+
19+
20+
int main() {
21+
#ifdef INSANE
22+
clock_t tStart = clock();
23+
freopen("int.txt", "r", stdin);
24+
freopen("ans.txt", "w", stdout);
25+
#endif
26+
27+
FASTERIO; // comment when use scanf and printf
28+
29+
dl storage [1000007];
30+
storage[0]=0;
31+
for(int i=1; i<=1000000; i++) storage[i]=storage[i-1]+log10(i);
32+
33+
int tt,caseno=1; cin>>tt;
34+
while(caseno<=tt){
35+
cout<<"Case "<<caseno<<": ";
36+
caseno++;
37+
int n, base; cin>>n>>base;
38+
int digits = storage[n]/log10(base)+1;
39+
cout<<digits<<"\n";
40+
}
41+
42+
#ifdef INSANE
43+
fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
44+
#endif
45+
return 0;
46+
}

0 commit comments

Comments
 (0)