問題一覧 > 通常問題

No.885 Remainder Query

レベル : / AI推定難易度 : 1375 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 164
作問者 : QCFium / テスター : ynymxiaolongbao
お気に入りにしたユーザー ProblemId : 3163 / 自分の提出
問題文最終更新日: 2019-09-13 23:25:15
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 223 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。