CMED06-Editorial

Problem Name
Find Next

Author: Uttam Singh
Tester: Vivek Solanki
Editorialist: Atharva Maheshwari

Difficulty
Cake-Walk

Pre-Requisites
Math, AP

PROBLEM
You are given three integers L,M,N. Where L and M are randomly picked consecutive integers in an unknown AP(Arithmetic Progression) you need to find the N’th number after M in AP.

Explanation
We need to find Nth term after a term in AP. We know that common difference in AP is difference between two consecutive terms. So D=M-L, now the Nth term after M is M+(N*D).

Solutions

#include <iostream>
using namespace std;

int main() 
{
	int T,L,M,N;
	cin>>T;
	for(int i=0;i<T;i++)
	{
	    cin>>L>>M>>N;
	    cout<<((M-L)*N)+M<<endl;
	}
	return 0;
}