0

Question

Hello everyone The question is we have 3 input x,y,z and the condition we want to fulfill is that i*x+y==z print value of i and if i*x+y!=z print the value of i in which sum i*x+y is nearest to z . Example like 2 5 11 So i*2+5<=11 print 3 2nd input 4,10,20 So i*4+10<=20 18<=20 Value of i which nearest to z is 2 I solved the 1 input My code t=int(input()) for i in range(t): X,Y,Z=map(int,input().split()) for i in range(0,Z): if i*X+Y<=Z: print(i) I'm stuck in the 2nd input?

4th May 2022, 3:19 PM
Akash Gupta
Akash Gupta - avatar
2 Answers
+ 2
Is the lower value always the nearest?
4th May 2022, 3:44 PM
Oma Falk
Oma Falk - avatar
+ 1
Try this way: if I*x+y==z : print(I) break else : if I*x+y < z : continue else : print(i-1) break #its an algorithm.
4th May 2022, 3:30 PM
Jayakrishna 🇼🇳