返回题库

缺失的两个整数

Missing Integers

专题
Brainteaser / 脑筋急转弯
难度
L4

题目详情

从 1 到 100 的整数中缺少了两个不同的数。现在给你剩下的 98 个不同整数。

问:如何确定缺失的两个整数?

We have 98 distinct integers from 1 to 100. Which two are missing?

解析

设缺失数为 x,yx,y,已知其余数为 z1,,z98z_1,\dots,z_{98}

利用总和与平方和:

x+y=5050i=198zi,x+y=5050-\sum_{i=1}^{98}z_i, x2+y2=338350i=198zi2.x^2+y^2=338350-\sum_{i=1}^{98}z_i^2.

(x+y)2=x2+y2+2xy(x+y)^2=x^2+y^2+2xy

可解出 xyxy,从而 x,yx,y 是方程 t2(x+y)t+xy=0t^2-(x+y)t+xy=0 的两根,可唯一确定。


Original Explanation

Let the 98 distinct integers be z1,z2,,z98z_1, z_2, \dots, z_{98}. If the missing numbers are xx and yy, we know:

  1. x+y+i=198zi=n=1100n=5050.x + y + \sum_{i=1}^{98} z_i = \sum_{n=1}^{100} n = 5050.
  2. x2+y2+i=198zi2=n=1100n2=100×101×2016=338350.x^2 + y^2 + \sum_{i=1}^{98} z_i^2 = \sum_{n=1}^{100} n^2 = \frac{100 \times 101 \times 201}{6} = 338350.

So from the sum and the sum of squares, you can solve for xx and yy uniquely.