Sunday, February 28, 2016

LightOJ - 1045 - Digits of Factorial

  1. /****************#####    بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم   #####******************
  2. __________________________________________________________________________
  3. ######################  Ya-Seen Arafat(ACWizard) #########################
  4. ######################        UAP-CSE-33B        #########################
  5. *************************************************************************/
  6. #include <bits/stdc++.h>
  7. #define ll long long
  8. #define S 1000003
  9. using namespace std;
  10.  
  11. double cuS[S];
  12.  
  13. void cumulativeSum(){
  14.     cuS[1] = log((double)1);
  15.     for(int i = 2; i < S; i++){
  16.         cuS[i] = cuS[i-1] + log((double)i);
  17.     }
  18. }
  19.  
  20. int main(){
  21.     int  t, cs = 0, n, base;
  22.     cumulativeSum();
  23.     scanf("%d"&t);
  24.     while(t--){
  25.         scanf("%d %d"&n, &base);
  26.         double value = cuS[n];
  27.         value /= log((double)base);
  28.         ll ans = value;
  29.         ans += 1;
  30.         printf("Case %d: %lld\n"++cs, ans);
  31.     }
  32.     return 0;
  33. }

No comments:

Post a Comment