CF1548D2.Gregor and the Odd Cows (Hard)
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the hard version of the problem. The only difference from the easy version is that in this version the coordinates can be both odd and even.
There are n fence-posts at distinct coordinates on a plane. It is guaranteed that no three fence posts lie on the same line.
There are an infinite number of cows on the plane, one at every point with integer coordinates.
Gregor is a member of the Illuminati, and wants to build a triangular fence, connecting 3 distinct existing fence posts. A cow strictly inside the fence is said to be enclosed. If there are an odd number of enclosed cows and the area of the fence is an integer, the fence is said to be interesting.
Find the number of interesting fences.
输入格式
The first line contains the integer n ( 3≤n≤6000 ), the number of fence posts which Gregor can choose to form the vertices of a fence.
Each of the next n line contains two integers x and y ( 0≤x,y≤107 , where (x,y) is the coordinate of a fence post. All fence posts lie at distinct coordinates. No three fence posts are on the same line.
输出格式
Print a single integer, the number of interesting fences. Two fences are considered different if they are constructed with a different set of three fence posts.
输入输出样例
输入#1
3 0 0 2 0 0 4
输出#1
1
输入#2
4 1 8 0 6 5 2 5 6
输出#2
1
输入#3
10 170 59 129 54 5 98 129 37 58 193 154 58 24 3 13 138 136 144 174 150
输出#3
29
说明/提示
In the first example, there is only 1 fence. That fence is interesting since its area is 4 and there is 1 enclosed cow, marked in red.
In the second example, there are 4 possible fences. Only one of them is interesting however. That fence has an area of 8 and 5 enclosed cows.