euisblue
6749. Next in line

6749 - Next in line

You know a family with three children. Their ages form an arithmetic sequence: the difference in ages between the middle child and youngest child is the same as the difference in ages between the oldest child and the middle child. For example, their ages could be 5, 10 and 15, since both adjacent pairs have a difference of 5 years.

Given the ages of the youngest and middle children, what is the age of the oldest child?

C++

1#include <bits/stdc++.h> 2using namespace std; 3int main(void) { 4 ios::sync_with_stdio(0); 5 cin.tie(0); 6 7 int a, b; 8 cin >> a >> b; 9 cout << b+(b-a) << endl; 10 return 0; 11}