import sys
sys.stdin=open('input.txt','r')

n, k = map(int,input().split())
count = 0

while True:
    if n == 1:
        break
    if n % k != 0:
        n = n-1
        count += 1
    else:
        n = n // k
        count += 1

print(n,k, count)