421. Yo-Yo

 

Toy yo-yo consists of a coil, which is wound a thread. If, holding the end of the thread to release the spool, it will be rotating, first drop down, and then by inertia to rise. But the height to which the coil will rise, will be k times less than the height from which she sank. We assume that the coil is stopped, if the height of another rise is less or equal than 1.

Write a program that the length of strings l and the coefficient k counts the number of ascents coil to stop. For example, let l = 17 and k = 2, then the coil will rise to the heights of 8.5, 4.25, 2.125, 1.0625, and then stops. So we get 4 lifts.

 

Input. Two integers l (1 ≤ l ≤ 109) and k (2 ≤ k ≤ 100).

 

Output. Print the number of ascents.

 

Sample input

Sample output

17 2

4

 

 

SOLUTION

loops

 

Algorithm analysis

Simulate the process of moving the coil and count the number of its ascents. Let l is a current height of the coil. After dropping it will rise only if the height of current rise is greater than 1. If the height of the rise will be no more than 1, this rise will not be counted (the coil will stop).

 

Algorithm realization

Read the input data.

 

scanf("%lf %lf",&l,&k);

 

Ñount the number of coil lifts in the variable res.

 

res = 0;

 

Let the coil is located at the height l. After releasing it will rise only if the height of current rise is greater than 1 (otherwise assume the coil stops). It’s possible when an inequality l / k > 1 holds.

 

while(l / k > 1.0)

{

  l /= k;

  res++;

}

 

Print the answer.

 

printf("%d\n",res);   

 

Java realization

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    double l = con.nextDouble();

    double k = con.nextDouble();

    int res = 0;

    while(l / k > 1.0)

    {

      l /= k;

      res++;

    }

    System.out.println(res);

    con.close();

  }

}

 

Python realization

Read the input data.

 

l,k = map(float,input().split())

 

Ñount the number of coil lifts in the variable res.

 

res = 0

 

Let the coil is located at the height l. After releasing it will rise only if the height of current rise is greater than 1 (otherwise assume the coil stops). It’s possible when an inequality l / k > 1 holds.

 

while l / k > 1:

  l /= k

  res += 1

 

Print the answer.

 

print(res)