Skip to content

Commit 71a347e

Browse files
authored
Create Richie Rich.c
1 parent 867262b commit 71a347e

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

Codechef Problems/Richie Rich.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Chef aims to be the richest person in Chefland by his new restaurant franchise. Currently, his assets are worth A billion dollars and have no liabilities. He aims to increase his assets by X billion dollars per year.
2+
3+
Also, all the richest people in Chefland are not planning to grow and maintain their current worth.
4+
5+
To be the richest person in Chefland, he needs to be worth at least B billion dollars. How many years will it take Chef to reach his goal if his value increases by X billion dollars each year?
6+
7+
Input
8+
The first line contains an integer T, the number of test cases. Then the test cases follow.
9+
Each test case contains a single line of input, three integers A, B, X.
10+
Output
11+
For each test case, output in a single line the answer to the problem.
12+
13+
Constraints
14+
1≤T≤21 000
15+
100≤A<B≤200
16+
1≤X≤50
17+
X divides B−A
18+
19+
Sample Input
20+
3
21+
100 200 10
22+
111 199 11
23+
190 200 10
24+
Sample Output
25+
10
26+
8
27+
1
28+
Explanation
29+
Test Case 1: Chef needs to increase his worth by 200−100=100 billion dollars and his increment per year being 10 billion dollars, so it will take him 10010=10 years to do so.
30+
31+
Test Case 2: Chef needs to increase his worth by 199−111=88 billion dollars and his increment per year being 11 billion dollars, so it will take him 8811=8 years to do so.
32+
33+
Test Case 3: Chef needs to increase his worth by 200−190=10 billion dollars and his increment per year being 10 billion dollars, so it will take him 1010=1 year to do so. */
34+
35+
36+
#include <stdio.h>
37+
38+
int main(void) {
39+
40+
int t,a,b,x;
41+
scanf("%d",&t);
42+
43+
int i;int time[t-1];
44+
for(i=0;i<t;i++)
45+
{
46+
scanf("%d %d %d",&a,&b,&x);
47+
time[i]=(b-a)/x;
48+
49+
}
50+
for(i=0;i<t;i++)
51+
{
52+
53+
printf("%d\n",time[i]);
54+
55+
}
56+
57+
return 0;
58+
}

0 commit comments

Comments
 (0)