No.854 Fair Apple Distribution
タグ : / 解いたユーザー数 75
作問者 :
CuriousFairy315
/ テスター :
tatyam
Problem Statement
The fairy has $N$ boxes, and the $i$-th box contains $A_i$ apples.
The fairy is about to hold a banquet with many fairy friends, and plans to open some of the boxes and distribute the apples.
The fairy has come up with $Q$ plans. In the $i$-th plan, $P_i$ fairies will come, and the fairy intends to open all the boxes in $[L_i, R_i]$ and share the apples inside.
At this time, by the power of magic, $\prod_{j=L_i}^{R_i} A_j$ apples can be taken out.
For each plan, output Yes if the apples taken out can be distributed equally among exactly $P_i$ fairies, and NO if there will inevitably be a remainder.
Input
$N$ $A_1$ $A_2$ $\cdots$ $A_N$ $Q$ $P_1$ $L_1$ $R_1$ $P_2$ $L_2$ $R_2$ $\vdots$ $P_Q$ $L_Q$ $R_Q$
Constraints
・$1 \leq N, Q \leq 10^5$
・$0 \leq A_i \leq 2 \times 10^3$
・$1 \leq L_i \leq R_i \leq N$
・$1 \leq P_i \leq 10^9$
・All inputs are integers
Output
On the $i$-th line, output Yes if $\prod_{j=L_i}^{R_i} A_j$ is divisible by $P_i$, and NO if it is not.
Print a newline at the end.
Sample
Sample 1
Input
3 6 4 6 1 2 2 3
Output
Yes
The product of the interval $[2, 3]$ is $24$, which is divisible by $2$, so output Yes.
Sample 2
Input
5 1 1 1 1 1 2 2 2 4 1 2 4
Output
NO Yes
For the first line, the product of the interval $[2, 4]$ is $1$, which is not divisible by $2$, so output NO.
For the second line, the product of the interval $[2, 4]$ is $1$, which is divisible by $1$, so output Yes.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。