PROBLEM LINK:
Author: Ishpreet
Tester: Karan
DIFFICULTY:
SIMPLE
PROBLEM:
There are total N stairs. A person climbs A stairs upwards in day and comes downstairs in night by B stairs. Find number of days person will take to reach the top of staircase.
EXPLANATION:
Let us start by solving the problem day wise.
Day1: A Night1: A-B
Day2: (A-B)+A Night2: 2*(A-B)
Day3: 2*(A-B)+A Night3: 3(A-B)
…
DayX: (A - B) * (X - 1) + A,
Let us assume, on day X, he crossed N stairs.
So,
(A - B) * (X - 1) + A >= N
AX - BX + B >= N
X (A - B) >= N - B
X >= (N - B) / (A - B)
All we need is the integer value of X which is >= (N - B) / (A - B).