Codeforces Round #278 Editorial [problem:488A]
--------------
The answer $b$ is very small (usually no larger than $10$), because one of $a+1,a+2, \cdots, a+10$ has its last digit be $8$.
However, $b$ can exceed $10$ when $a$ is negative and close to $0$. The worst case is $a=-8$, where $b=16$.
Anyway $b$ is rather small, so we can simply try $b$ from $1$, and check whether $a+b$ has a digit 8.
[problem:488B]
--------------
Let's sort the four numbers in ascending order: $a, b, c, d$ (where $x_1,x_2,x_3,x_4$ are used in problem statement). So $\frac{a+b+c+d}{4}=\frac{b+c}{2}=d-a$.
With some basic math, we can get $a:d=1:3$ and $a+d=b+c$.
**Solution 1:**
If $n=0$, just output any answer (such as ${1,1,3,3}$). If $n=1$, just output ${x,x,3x,3x}$, where $x$ is the known number. If $n=4$, just check whether the four known numbers meet the condition.
If $n=2$, let $x,y$ denote the known numbers ($x \leq y$). No solution exists if $3x < y$. Otherwise we can construct a solution ${x,y,4x-y,3x}$ ...
a_n = n! \equiv 0 \mod n$. If $n$ occurs in \{a_1,…,a_{n-1}\} in the prefix
product sequence $0
Full text and comments »