Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

First k digits of n^n

$
0
0

It is related to problem :http://www.codechef.com/problems/MARCHA4 where we are supposed to find first and last k digits of n^n. To find first k digits i have seen people using some log and floor functions..complete code is below:

long int firstKdigits(long long n,int k)

{ long double x, y;

x = n*log10(n);

y = floor(pow(10,x-floor(x) +k-1));

return ((int)y);

}

Can someone provide me proof of this..how it gives first k digits??


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>