Given a number n , find the first k digits of n ^ n | C # program to find the first k digits of n ^ n ; function that manually calculates n ^ n and then removes digits until k digits remain ; take log10 of n ^ n . log10 ( n ^ n ) = n * log10 ( n ) ; We will now try to separate the decimal and integral part of the / product . The floor function returns the smallest integer less than or equal to the argument . So in this case , product - floor ( product ) will give us the decimal part of product ; we will now exponentiate this back by raising 10 to the power of decimal part ; We now try to find the power of 10 by which we will have to multiply the decimal part to obtain our final answer ; driver function
using System ; class GFG { public static long firstkdigits ( int n , int k ) { double product = n * Math . Log10 ( n ) ; double decimal_part = product - Math . Floor ( product ) ; decimal_part = Math . Pow ( 10 , decimal_part ) ; double digits = Math . Pow ( 10 , k - 1 ) ; return ( ( long ) ( decimal_part * digits ) ) ; } public static void Main ( ) { int n = 1450 ; int k = 6 ; Console . Write ( firstkdigits ( n , k ) ) ; } }