Richie Rich Codechef Solution

Hello Programmers In this post, you will know how to solve the Richie Rich Codechef Solution.

Ezoicreport this adRichie Rich Codechef Solution
Richie Rich Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Ezoicreport this adProblem

Chef aims to be the richest person in Chefland by his new restaurant franchise. Currently, his assets are worth AA billion dollars and have no liabilities. He aims to increase his assets by XX billion dollars per year.

Also, all the richest people in Chefland are not planning to grow and maintain their current worth.

To be the richest person in Chefland, he needs to be worth at least BB billion dollars. How many years will it take Chef to reach his goal if his value increases by XX billion dollars each year?

Input

  • The first line contains an integer TT, the number of test cases. Then the test cases follow.
  • Each test case contains a single line of input, three integers AA, BB, XX.

Output

For each test case, output in a single line the answer to the problem.

Constraints

  • 1≤T≤21 0001≤T≤21 000
  • 100≤A<B≤200100≤A<B≤200
  • 1≤X≤501≤X≤50
  • XX divides B−AB−A

Subtasks

Subtask #1 (100 points): Original constraints

Sample Input

3
100 200 10
111 199 11
190 200 10

Sample Output

10
8
1

Explanation

Test Case 11: Chef needs to increase his worth by 200−100=100200−100=100 billion dollars and his increment per year being 1010 billion dollars, so it will take him 10010=1010010=10 years to do so.

Test Case 22: Chef needs to increase his worth by 199−111=88199−111=88 billion dollars and his increment per year being 1111 billion dollars, so it will take him 8811=88811=8 years to do so.

Test Case 33: Chef needs to increase his worth by 200−190=10200−190=10 billion dollars and his increment per year being 1010 billion dollars, so it will take him 1010=11010=1 year to do so.

Richie Rich CodeChef Solutions in JAVA

import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args) throws IOException
	{
		try{
			Scanner sc = new Scanner(System.in);
			int t = sc.nextInt();
			for(int i=0;i<t;i++){
			    int A = sc.nextInt();
			    int B = sc.nextInt();
			    int X = sc.nextInt();
			    int need_to_increase = B - A;
			    int years = need_to_increase / X;
			    System.out.println(years);
			}
		}catch(Exception e){
			return;
		}
	}
}
Ezoicreport this ad

Richie Rich CodeChef Solutions in CPP

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int a,b,x;
        cin>>a>>b>>x;
        int z=(b-a)/x;
        cout<<z<<endl;
    }
    return 0;
}

Richie Rich CodeChef Solution in Python

t=int(input())
for i in range(t):
    a,b,c=map(int,input().split())
    print((b-a)//c)

Disclaimer: The above Problem (Richie Rich) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Chef and Demonetisation Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad