QM12A - editorial

PROBLEM LINK:

Practice

Contest

Author: Chandan Boruah
Tester: Chandan Boruah
Editorialist: Chandan Boruah

DIFFICULTY:

SIMPLE

PREREQUISITES:

Maths

PROBLEM:

Given the sequence This is a sequence 1, N+1, 2, N+2, 3, N+3, 4, N+4, 5, …… N, 2*N and two consecutive numbers in the sequence, one in odd position and the other in even position, print the last number in the sequence.

QUICK EXPLANATION:

The answer is 2*(second number-first number)

EXPLANATION:

Since difference between consecutive numbers reveals N (example N+1-1, or N+2-2) and the last digit is 2* N, so the solution that is the last number is 2* (second number-first number)

AUTHOR’S AND TESTER’S SOLUTIONS:

using System;
using System.Collections.Generic;
class some
{
	public static void Main()
	{
		string[]ss=Console.ReadLine().Split();
		long a=long.Parse(ss[0]);
		long b=long.Parse(ss[1]);
		Console.WriteLine(2*(b-a));
	}
}