While10. An integer N (> 1) is given. Find the largest integer K for which the inequality \(3^K < N\) holds.

Solution in Python 3:

import random

N = random.randrange(2,10000)
#N = 100
print('N = ', N)

K = 0
P = 1
while P <= N:
P *= 3
K += 1
K -= 1
print("K = {0}, 3^K = {1}, 3^(K+1) = {2}".format(K,3**K,3**(K+1)))