#P10907. [蓝桥杯 2024 国 B] 蚂蚁开会

    ID: 12362 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学2024数论哈希 hashing蓝桥杯国赛

[蓝桥杯 2024 国 B] 蚂蚁开会

Problem Description

On a 2D plane, there are nn ants. Each ant has a line segment as its movement range. The two endpoints of the ii-th ant’s movement range are (uix,uiy)(u_i^x, u_i^y) and (vix,viy)(v_i^x, v_i^y). Now the ants plan to set meeting centers at the intersection points of these segments. To save as much budget as possible, they decide to set meeting centers only at intersection points that are lattice points (points with integer coordinates). How many meeting centers need to be set?

Input Format

The input consists of n+1n + 1 lines.

The first line contains a positive integer nn.

The next nn lines each contain 44 integers separated by spaces, representing uix,uiy,vix,viyu_i^x, u_i^y, v_i^x, v_i^y.

Output Format

Output one line containing one integer, representing the answer.

4
0 0 4 4
0 4 4 0
2 0 0 4
2 1 2 3
2

Hint

Sample Explanation.

Among all segments, there are 33 distinct intersection points: (0,4)(0, 4), (43,43)(\frac{4}{3}, \frac{4}{3}), and (2,2)(2, 2). Among them, there are 22 lattice points: (0,4)(0, 4) and (2,2)(2, 2).

Constraints.

For 20%20\% of the testdata, it is guaranteed that 0uix,uiy,vix,viy1000 \le u_i^x, u_i^y, v_i^x, v_i^y \le 100.

For 100%100\% of the testdata, it is guaranteed that n500n \le 500 and 0uix,uiy,vix,viy100000 \le u_i^x, u_i^y, v_i^x, v_i^y \le 10000. It is guaranteed that no ant’s movement range degenerates into a point. It is not guaranteed that the number of intersection points between any two segments is finite.

Translated by ChatGPT 5