CF1248A.Integer Points
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
DLS and JLS are bored with a Math lesson. In order to entertain themselves, DLS took a sheet of paper and drew n distinct lines, given by equations y=x+pi for some distinct p1,p2,…,pn.
Then JLS drew on the same paper sheet m distinct lines given by equations y=−x+qi for some distinct q1,q2,…,qm.
DLS and JLS are interested in counting how many line pairs have integer intersection points, i.e. points with both coordinates that are integers. Unfortunately, the lesson will end up soon, so DLS and JLS are asking for your help.
DLS 和 JLS 对一节数学课感到无聊。为了自娱自乐,DLS 拿出一张纸,画了 n 条互不相同的直线,其方程为 y=x+pi,其中 p1,p2,…,pn 互不相同。
接着,JLS 在同一张纸上画了 m 条互不相同的直线,其方程为 y=−x+qi,其中 q1,q2,…,qm 互不相同。
DLS 和 JLS 想知道:有多少对直线的交点坐标均为整数(即交点的横、纵坐标均为整数)?但课程即将结束,因此 DLS 和 JLS 向你求助。
输入格式
The first line contains one integer t (1≤t≤1000), the number of test cases in the input. Then follow the test case descriptions.
The first line of a test case contains an integer n (1≤n≤105), the number of lines drawn by DLS.
The second line of a test case contains n distinct integers pi (0≤pi≤109) describing the lines drawn by DLS. The integer pi describes a line given by the equation y=x+pi.
The third line of a test case contains an integer m (1≤m≤105), the number of lines drawn by JLS.
The fourth line of a test case contains m distinct integers qi (0≤qi≤109) describing the lines drawn by JLS. The integer qi describes a line given by the equation y=−x+qi.
The sum of the values of n over all test cases in the input does not exceed 105. Similarly, the sum of the values of m over all test cases in the input does not exceed 105.
In hacks it is allowed to use only one test case in the input, so t=1 should be satisfied.
第一行包含一个整数 t(1≤t≤1000),表示输入中测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105),表示 DLS 所画直线的数量。
每个测试用例的第二行包含 n 个互不相同的整数 pi(0≤pi≤109),用于描述 DLS 所画的直线。整数 pi 对应一条由方程 y=x+pi 给出的直线。
每个测试用例的第三行包含一个整数 m(1≤m≤105),表示 JLS 所画直线的数量。
每个测试用例的第四行包含 m 个互不相同的整数 qi(0≤qi≤109),用于描述 JLS 所画的直线。整数 qi 对应一条由方程 y=−x+qi 给出的直线。
输入中所有测试用例的 n 值之和不超过 105;同理,所有测试用例的 m 值之和也不超过 105。
在 hack 中,输入仅允许包含一个测试用例,因此必须满足 t=1。
输出格式
For each test case in the input print a single integer — the number of line pairs with integer intersection points.
对于输入中的每个测试用例,输出一个整数——具有整数交点的直线对的数量。
输入输出样例
输入#1
3 3 1 3 2 2 0 3 1 1 1 1 1 2 1 1
输出#1
3 1 0
说明/提示
The picture shows the lines from the first test case of the example. Black circles denote intersection points with integer coordinates.

图片展示了示例中第一个测试用例的直线。黑色圆圈表示具有整数坐标的交点。

输入解题思路,AI测评打分。不知道怎么写?