Bismillahir Rahmanir Rahim
Find digit of any number using this method: Floor[Log(b) N] + 1
So at first pre-calculate of any factorial digit then convert it to any base
or that is asked by the problem author.
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
double base_10[1000009];
void base_10_cal()
{
base_10[0]=0;
for(ll i=1;i<=1000000;i++) base_10[i]=base_10[i-1]+log10(i);
}
int main()
{
base_10_cal();
ll tst,num,base,ca=1;
scanf("%lld",&tst);
while(tst--)
{
scanf("%lld%lld",&num,&base);
ll baby=(base_10[num]/log10(base));
printf("Case %lld: %lld\n",ca++,baby+1);
}
return 0;
}
///Alhamdulillah
Problem Link: https://lightoj.com/problem/digits-of-factorial
Comments
Post a Comment