views:

160

answers:

4

This is a homework, but please give me some ideas, i have no idea what to do. Here's the task:

For given integers N and K (1 <= N, K <= 2000000000) you have to find the number of digits of N^K.

Is there any formula or something ? Because i tried solving it by simply powering N**K but it's not working for large values and the program simply freezes because of the calculations. I am looking for some fast way maybe some math formula like i said before.

+3  A: 

Hint: Logarithm.

KennyTM
+12  A: 

The 10 base log of N should give you the number of digits in it. This must be enough as a hint :-)

Péter Török
+1  A: 

Try to think of a math operation that tells you the number of digits of a number. Apply that to N**K and see if you can't simplify the formula.

clahey
+2  A: 

Hints: Log (X ^ Y) = Y * Log (X)

The following numbers have 4 digits; the integer part of the decimal logarithm is 4 - 1 = 3. Log 1000 = 3, Log (9999) = 3,9999565683801924896154439559762

Thingol