No.885 Remainder Query
タグ : / 解いたユーザー数 164
作問者 :
QCFium
/ テスター :
ynymxiaolongbao
Problem Statement
You are given an integer sequence $A(A_1,A_2,\dots\,A_N)$ of length $N$. Process $Q$ queries as described below.
(Query) :
In the $i$-th query, an integer $X_i$ is given. Replace every element of the sequence $A$ with its remainder when divided by $X_i$,
and then output the sum of the sequence.
Input
$N$ $A_1\ A_2\ A_3\ \dots\ A_N$ $Q$ $X_1\ X_2\ X_3\ \dots\ X_Q$
$1 \le N \le 10^5$
$0 \le A_i \le 10^9$
$1 \le Q \le 10^5$
$1 \le X_i \le 10^9$
All input values are integers.
Output
For each query, output the answer followed by a newline.
Sample
Sample 1
Input
4 7 2 4 9 3 6 8 3
Output
10 10 4
In the first query, every element of the sequence $A$ is replaced with its remainder when divided by 6.
The sequence $A$ changes from $[7, 2, 4, 9]$ to $[1, 2, 4, 3]$, and its sum is 10, so output 10.
In the 2nd query, the sequence stays $[1, 2, 4, 3]$, so output 10.
In the 3rd query, it becomes $[1, 2, 1, 0]$, so output 4.
Sample 2
Input
10 3 11 6 2 34 21 44 8 0 2 10 50 34 42 36 26 8 16 13 24 4
Output
131 63 63 63 63 23 23 23 23 15
Sample 3
Input
10 10 9 8 7 6 5 4 3 2 1 10 10 9 8 7 6 5 4 3 2 1
Output
45 36 28 21 15 10 6 3 1 0
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。