목차

기벡을 안배운다고?

ps
링크acmicpc.net/…
출처BOJ
문제 번호28132
문제명기벡을 안배운다고?
레벨골드 1
분류

기하학

시간복잡도O(nlogm)
인풋사이즈n<=200,000, m<=10^9
사용한 언어Python 3.13
제출기록72432KB / 480ms
최고기록364ms
해결날짜2025/02/18

풀이

코드

"""Solution code for "BOJ 28132. 기벡을 안배운다고?".

- Problem link: https://www.acmicpc.net/problem/28132
- Solution link: http://www.teferi.net/ps/problems/boj/28132

Tags: [math]
"""

import collections
import math
import sys


def main():
    N = int(sys.stdin.readline())

    counter = collections.Counter()
    zero_vec_count = 0
    for _ in range(N):
        x, y = [int(x) for x in sys.stdin.readline().split()]
        if x == y == 0:
            zero_vec_count += 1
        else:
            g = math.gcd(x, y)
            counter[x // g, y // g] += 1

    zero_nonzero_pair_count = zero_vec_count * (N - zero_vec_count)
    zero_pair_count = zero_vec_count * (zero_vec_count - 1) // 2
    nonzero_pair_count = sum(
        count * counter[y, -x] for (x, y), count in counter.items()
    )

    answer = zero_nonzero_pair_count + zero_pair_count + nonzero_pair_count

    print(answer)


if __name__ == '__main__':
    main()