#H2026TEST1. Divisor Friendship
Divisor Friendship
Background
There are robots in Workshop Alpha and robots in Workshop Beta. Every robot has a unique-looking serial number, and two robots become compatible when the serial number of the Alpha robot is a divisor of the serial number of the Beta robot.
The factory wants to know how many compatible cross-workshop pairs can be formed.
Problem
You are given two sequences:
- : serial numbers of the robots in Workshop Alpha;
- : serial numbers of the robots in Workshop Beta.
Count the number of pairs such that , , and
Input Format
The first line contains two integers and , separated by a space.
The second line contains integers .
The third line contains integers .
Output Format
Output a single integer: the number of compatible pairs.
Samples
Sample 1
Input:
2 3
2 3
2 6 9
Output:
4
Explanation:
divides and ; divides and . There are compatible pairs.
Sample 2
Input:
3 3
2 2 5
4 10 5
Output:
6
Explanation:
Each of the two 's matches and ; the single matches and . The total is .
Constraints
The answer may exceed the range of a 32-bit signed integer.
相关
在下列比赛中: