CodechefJun 28, 2025

Reach fast

Hazrat Ali

Codechef

Chef is standing at coordinate A while Chefina is standing at coordinate B.

In one step, Chef can increase or decrease his coordinate by at most K.

Determine the minimum number of steps required by Chef to reach Chefina.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of three integers A,B, and K, the initial coordinate of Chef, the initial coordinate of Chefina and the maximum number of coordinates Chef can move in one step.

Output Format

For each test case, output the minimum number of steps required by Chef to reach Chefina.

Constraints

  • 1≤T≤1000
  • 1≤A,B≤100
  • 1≤K≤100

Sample 1:

Input
4
10 20 3
36 36 5
50 4 100
30 4 2

Output
4
0
1
13
 

Solution

import math

t = int(input())
while t != 0:
    x, y, k = map(int, input().split())
    val = abs(y - x)
    res = math.ceil(val / k)
    print(int(res))
    t -= 1






Comments