Thursday, July 30, 2015

1045 - Digits of Factorial

#include<bits/stdc++.h>
using namespace std;
double arr[1000005];
int main()
{
    long long T,n,b,c=1,i;
    arr[0]=0.0;arr[1]=0.0;
    for(i=2;i<=1000005;i++)
        arr[i] = log(i)+arr[i-1];
//    freopen("check.txt","r",stdin);
    scanf("%lld",&T);
    while(T--)
    {
        scanf("%lld%lld",&n,&b);
        printf("Case %lld: %lld\n",c++,(long long)((arr[n]/log(b)+1)));
    }
    return 0;
}

No comments:

Post a Comment

Triathlon

Triathlon - CodeChef # include < bits/stdc++.h > using namespace std ; # define fi first # define se second # define mp ...