#P5887. Ringed Genesis

Ringed Genesis

Description

There is a long ring made by connecting nn cells end to end, numbered from 00 to n1n-1 in order.

There is also an animal called a rabbit. The rabbit’s step length is kk. If the rabbit is currently on the ii-th cell, then in the next second it will jump to the ((i+k)modn)((i+k)\bmod n)-th cell.

Now there are mm rabbits. The initial cell of the ii-th rabbit is the pip_i-th cell. As time goes by, some cells are visited by rabbits, while some cells are never visited.

You need to find how many cells can never be visited by any rabbit.

Input Format

Read input from standard input.

The first line contains three positive integers n,m,kn, m, k, representing the ring length, the number of rabbits, and the step length.

The second line contains mm non-negative integers p1,p2,,pmp_1, p_2, \dots, p_m, representing the initial cells of the rabbits.

Output Format

Write output to standard output.

Output one line with one integer, which is the answer.

4 2 2
0 1

0
4 2 2
0 2

2

Hint

Subtask 1 (10%10\%): k=1k = 1.

Subtask 2 (20%20\%): knk \mid n, i.e. gcd(k,n)=k\gcd(k, n) = k.

Subtask 3 (25%25\%): 1n10001 \leq n \leq 1000, 1m10001 \leq m \leq 1000.

Subtask 4 (45%45\%): no special constraints.

For all testdata, 1n1061 \leq n \leq 10^6, 1m1061 \leq m \leq 10^6, 1kn1 \leq k \leq n.

Translated by ChatGPT 5