Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Chef is currently standing at stair 0 and he wants to reach stair numbered X.
Chef can climb either Y steps or 1 step in one move.
Find the minimum number of moves required by him to reach exactly the stair numbered X.
For each test case, output the minimum number of moves required by him to reach exactly the stair numbered X.
Input:
4
4 2
8 3
3 4
2 1
Output:
2
4
3
2
Test case 1: Chef can make 2 moves and climb 2 steps in each move to reach stair numbered 4.
Test case 2: Chef can make a minimum of 4 moves. He can climb 3 steps in 2 of those moves and 1 step each in remaining 2 moves to reach stair numbered 8.
Test case 3: Chef can make 3 moves and climb 1 step in each move to reach stair numbered 3.
Test case 4: Chef can make 2 moves and climb 1 step in each move to reach stair numbered 2
# cook your dish here
t=int(input())
for i in range(t):
x,y=map(int,input().split())
if x%y==0:
print(x//y)
elif x%y==1:
print(x//y + 1)
else:
print(x//y + x-(x//y)*y)
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int x , y , z;
int temp;
cin>>x>>y;
temp=x;
z=x/y;
z+=temp%y;
cout<<z<<endl;
}
return 0;
}
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{
int a=sc.nextInt();
int b=sc.nextInt();
if(a<b)
{
System.out.println(a);
}
else if(a%b==0)
{
System.out.println(a/b);
}
else{
System.out.println((a/b)+(a%b));
}
t--;
}
}
}
In our experience, we suggest you solve this X Jumps CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the X Jumps CodeChef Solution
I hope this X Jumps CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>