PROBLEM LINK:
Author: Riddhish Lichade
Tester: Prathamesh Sogale
Editorialist: Yogesh Deolalkar
DIFFICULTY:
SIMPLE.
PREREQUISITES:
Math
PROBLEM:
A tussle year is considered to be lucky in BATU. No one knows what it is except you.
People in BATU want your help find when will the tussle year occur for their family. A tussle
year for a family is the one in which the age of the father is twice the age of his son. For
example, if the son’s age is 15, the father’s 30 and the grandfather’s age is 60 in a particular
year then it is a tussle year for the family.
Given the age of the 3 generations of a family, help people after how many years will the
tussle year occur for them. Print -1 if no tussle year occurs for their family.
QUICK EXPLANATION:
In tussle year the age of the father is twice the age of his son.
SOLUTIONS:
Setter's Solution
from sys import stdin
for _ in range(int(stdin.readline())):
s, f, g = map(int, stdin.readline().strip().split())
gap1=f-(2s)
gap2=g-(2f)
if(gap1==gap2):
print(gap1)
else:
print(-1)
Editorialist's Solution
#include
using namespace std;
int main()
{
int t;
cin >> t;
while (t–)
{
int s, f, g;
cin >> s >> f >> g;
if(2*(f-s)!=(g-f) || (s>f || f>g))
{
cout<<“-1”<<endl;
}
else
{
cout<<(f-2*s)<<endl;
}
}
return 0;
}