No.2620 Sieve of Coins
Problem Statement
There are $L$ coins on a desk.
Let coin $i$ ( $1 \le i \le L$ ) denote the $i$-th coin from the left.
Coins $A_1, \cdots, A_N$ are face up, and all other coins are face down.
Starting from this state, perform the following operation for $i = 1, \cdots, L$ in this order.
- If coin $i$ is face down, do nothing.
- If coin $i$ is face up, then for each integer $j$ ( $2 \le j \le \lfloor \frac{L}{i} \rfloor$ ), flip coin $i \times j$.
Input
$L$ $N$ $A_1$ $\cdots$ $A_N$
All test cases satisfy the following constraints.
- All input values are integers
- $1 \le L \le 10^{12}$
- $1 \le N \le 534$
- $1 \le A_1 \lt \cdots \lt A_N \le L$
- $A_i$ ($1 \le i \le N$) has no prime factor greater than or equal to $5$
sample_01.txt~sample_05.txt, subtask1_*.txt, subtask2_*.txt, subtask3_*.txt, subtask4_*.txt.Depending on the test case name, the following additional constraints are satisfied.
sample_01.txt~sample_05.txtcorrespond to Sample 1 through Sample 5subtask1_*.txt($11$ cases) satisfy $L \le 10^{5}$subtask2_*.txt($12$ cases) satisfy $N = 1$subtask3_*.txt($17$ cases) satisfy $N \le 20$subtask4_*.txt($13$ cases) have no additional constraints
Also, since test case names are not visible during the contest until you get AC, if you want to try a subtask, it is recommended to make cases that do not satisfy its constraints result in
Runtime Error, using an assert statement or similar.Output
Print the integer that is the answer on $1$ line. End the output with a newline.
Sample
Sample 1
Input
8 1 1
Output
6
The states of the coins change as follows.
In operation $4$, coin $4$ is face down, so coin $8$ stays as it is.
In operation $5$ and later, no coins are flipped.
Therefore, in the end, the $6$ coins $1, 2, 3, 5, 6, 7$ are face up.
| Number of operations | States of the coins |
|---|---|
| $0$ | Up, Down, Down, Down, Down, Down, Down, Down |
| $1$ | Up, Up, Up, Up, Up, Up, Up, Up |
| $2$ | Up, Up, Up, Down, Up, Down, Up, Down |
| $3$ | Up, Up, Up, Down, Up, Up, Up, Down |
| $4$ | Up, Up, Up, Down, Up, Up, Up, Down |
Sample 2
Input
8 3 1 2 3
Output
5
The states of the coins change as follows.
Operation $1$ turns coins $2, 3$ face down.
Thus, no flips occur in operations $2, 3$.
In operation $4$, coin $4$ is face up.
Therefore, coin $8$ changes from face up to face down.
In operation $5$ and later, no flips occur.
Thus, in the end, the $5$ coins $1, 4, 5, 6, 7$ are face up.
| Number of operations | States of the coins |
|---|---|
| $0$ | Up, Up, Up, Down, Down, Down, Down, Down |
| $1$ | Up, Down, Down, Up, Up, Up, Up, Up |
| $2$ | Up, Down, Down, Up, Up, Up, Up, Up |
| $3$ | Up, Down, Down, Up, Up, Up, Up, Up |
| $4$ | Up, Down, Down, Up, Up, Up, Up, Down |
Sample 3
Input
100000 8 1 2 3 4 6 8 9 12
Output
37999
This case satisfies the constraints of subtask1_*.txt, subtask3_*.txt, and subtask4_*.txt.
Sample 4
Input
1000000000000 1 1
Output
607927102274
This case satisfies the constraints of subtask2_*.txt, subtask3_*.txt, and subtask4_*.txt.
Sample 5
Input
1000000000000 8 1 2 3 4 6 8 9 12
Output
379954438788
This case satisfies the constraints of subtask3_*.txt and subtask4_*.txt.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
startcpp
Nachia