Count coprime pairs
Given an integer n (1 <= n <= 100000), count the number of unordered pairs (i, j) with 1 <= i < j <= n such that gcd(i, j) == 1 (i and j are coprime). For example, for n = 5 there are 9 coprime pairs. A naive O(n^2) gcd over all pairs is too slow at the upper bound.
Implement
count_coprime_pairs(n: int) → intExamples
in
[5]out9What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 30 min
solution.py
InputExpectedGot
[5]9not run yetsample