Codeforces Round 210 (Div. 1)
D
Levko and Sets
Codeforces
2600
原题
← CE →
翻译中…

Levko loves all sorts of sets very much.

翻译中…

Levko has two arrays of integers $*a*_{1}, *a*_{2}, ... , *a*_{*n*}$ and $*b*_{1}, *b*_{2}, ... , *b*_{*m*}$ and a prime number $*p*$. Today he generates $*n*$ sets. Let's describe the generation process for the $*i*$-th set:

翻译中…
  1. First it has a single number $1$.
  2. Let's take any element $*c*$ from this set. For all $*j*$ ($1 ≤ *j* ≤ *m*$) if number $(*c*·*a*_{*i*}^{*b*_{*j*}}) *mod* *p*$ doesn't occur in the set, then add it to the set.
  3. Repeat step $2$ as long as we can add at least one element to our set.
翻译中…

Levko wonders, how many numbers belong to at least one set. That is, he wants to know what size is the union of $*n*$ generated sets.

翻译中…

Input

翻译中…

The first line contains three integers $*n*$, $*m*$ and $*p*$ ($1 ≤ *n* ≤ 10^{4}$, $1 ≤ *m* ≤ 10^{5}$, $2 ≤ *p* ≤ 10^{9}$), $*p*$ is prime.

翻译中…

The second line contains space-separated integers $*a*_{1}, *a*_{2}, ... , *a*_{*n*}$ ($1 ≤ *a*_{*i*} < *p*$). The third line contains space-separated integers $*b*_{1}, *b*_{2}, ... , *b*_{*m*}$ ($1 ≤ *b*_{*i*} ≤ 10^{9}$).

翻译中…

Output

翻译中…

The single number — the size of the union of the sets.

翻译中…

样例

Input #1
1 1 7
2
5
Output #1
3
InputCopy OutputCopy
Input #2
1 2 7
2
2 4
Output #2
3
InputCopy OutputCopy
Input #3
2 1 7
1 6
2
Output #3
1
InputCopy OutputCopy
Input #4
2 1 7
1 6
5
Output #4
2
InputCopy OutputCopy
题目信息
题号
360D
时间限制
3 s
内存限制
256 MB
标签
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。