Light oj 1045 Digits of Factorial Solution
problem link : Light oj 1045
Explain: We know that 10 base number system digit of x number is =
⌊log10x⌋+1
According to the same way b base number system digit of x number is =
Accoding to the logarithm law:
We know
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
Solution in c++:
#include <bits/stdc++.h>
using namespace std;
double v[1000000];
int main()
{
long long int t,b,i,j,k,r,n;
for(int i=1; i<=1000000; i++)
v[i]=v[i-1] + log(i);
cin>>t;
for(k=1; k<=t; k++)
{
cin>>n>>b;
r=v[n]/log(b);
printf("Case %d: %lld\n", k,r+1);
}
return 0;
}
No comments