#Skip to menu

Missing pair

First read the problem description.

Let \(n=1000000\), \(s'\) be the sum of the numbers in input, \(s = \sum_{k=1}^n - s' = \frac{n*(n+1)}{2} - s'\)1, \(q'\) be the sum of the squares of the numbers in input, \(q = \sum_{k=1}^n k^2 - q' = \frac{2*n^3+3*n^2+n}{6} - q'\)2

Now let \(x+y = s\) and \(x^2+y^2=q\) if we put these two equations in a system and solve it we get \(x = \frac{s + \sqrt[2]{2*q-s^2}}{2}\) and \(y = \frac{s - \sqrt[2]{2*q-s^2}}{2}\).

Sample inputs:

  • Input 1: \(x = 950956\), \(y = 55729\)
  • Input 2: \(x = 149571\), \(y = 52368\)

  1. See Arithmetic progression↩︎

  2. See Sum of squares↩︎


Source code of the solution(s):
Tags: ,