소수 p와 두 집합 S, V가 주어질 때, V에 대한 유리식의 곱이 0이 되는 S의 원소 쌍 (a,b)의 개수를 센다.
어려움9수학정수론조합론해시맵아직 제출이 없습니다시간 제한4초메모리 제한512 MBIs it a programming contest?
You are given a prime number \(p\) and two subsets \(S\) and \(V\) of residues from \(0\) to \(p − 1\).
Your task is to find the number of pairs \((a, b)\) that satisfy the following set of equations:
All operations are performed modulo \(p\). Note that, when \(a \ne b\), the pairs \((a, b)\) and \((b, a)\) are considered different.
Division by zero is not allowed: when any of the two denominators turns into a zero, the congruence is considered false.
The first line contains a single integer \(p\) (\(2 \le p \le 10^6\), \(p\) is prime).
The second line contains a single integer \(n\): the size of \(S\) (\(0 \le n \le p\)).
The third line contains \(n\) distinct integers \(S_1, S_2, \dots , S_n\): the elements of \(S\) (\(0 \le S_i \le p − 1\)).
The fourth line contains a single integer \(m\): the size of \(V\) (\(0 \le m \le p\)).
The fifth line contains \(m\) distinct integers \(V_1, V_2, \dots , V_m\): the elements of \(V\) (\(0 \le V_i \le p − 1\)).
Print one integer: the number of solutions.