Light OJ 1045 – Digits of Factorial [solved]


/******************************************
Mobarak Hosen Shakil
ICE, Islamic University
ID: mhiceiuk(all), 29698(LOJ)
E-mail: mhiceiuk @ (Gmail/Yahoo/FB)
Blog: https://iuconvergent.wordpress.com
*******************************************/

#include
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define LL long long int
#define ULL unsigned LL

const int inf=1<<30;
const LL INF=1e18;
const int MOD=1e9+7;

double ndigits[1000006];

void Pre_Calculate()
{
    ///ndigits[0]=1;

    for(int i=1; i<=1000000; i++)
    {
        ndigits[i] = ndigits[i-1]+ log(i);
    }

}

int main()
{
    int tn, cn=0;
    scanf("%d", &tn);
    Pre_Calculate();
    while(tn--)
    {
        int n, b;
        scanf("%d%d", &n, &b);
        printf("Case %d: %lld\n", ++cn, (LL)(ndigits[n]/log(b) + 1));
    }
    return 0;
}

A novice competitive programmer. Studying Bachelor of Science in Information and Communication Engineering, Islamic University, Kushtia-7003.

Posted in Light OJ

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow IU Convergent on WordPress.com
Community!
Views
  • 29,867 views