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 =  
logbx+1

Accoding to the logarithm law:

   We know    
                               



   is the answer 



///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

    Most View Post

    Recent post

    RESTful APIs with CRUD Operations in Laravel 12| (2025)

      RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

    Powered by Blogger.