The One Polynomial Man
Time limit4sMemory limit512 MB
Count ordered pairs (a, b) from S where the rational expression in a and b, taken mod p, lands in V. Pairs with a zero denominator fail.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Hash map
- Solved
- No attempts yet
Problem
Is it a programming contest? You are given a prime and two subsets and of residues from to . Count the pairs that satisfy all three conditions: first, ; second, ; third, . All operations are performed modulo . When , the pairs and count as different. Division by zero is not allowed: if either denominator is zero, the congruence is considered false.
Input
The first line contains a prime (). The second line contains , the size of (). The third line contains the distinct elements (). The fourth line contains , the size of (). The fifth line contains the distinct elements ().
Output
Print one integer: the number of solutions.