Thursday 27 July 2017

Lightoj 1045 - Digits of Factorial

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define N 1000006
  4. double LOG[N];
  5. int main(){
  6.     for(int i = 1; i <N; i++){LOG[i] = log(i*1.00) + LOG[i-1];}
  7.     int ts;
  8.     cin>>ts;
  9.     for(int k = 1; k <= ts; k++){
  10.         int a, b;
  11.         scanf("%d%d"&a, &b);
  12.         printf("Case %d: %d\n",k, (int)(floor(LOG[a]/log(b*1.00))+1));
  13.     }
  14.     return 0;
  15. }

No comments:

Post a Comment

Most Featured Post

Lightoj 1159 - Batman

http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...