Skip to main content

Coprimality Census

Challenge on lesson: Final 2-B: Coprimality Census

CHALLENGE
Difficulty: advanced+25 XP

**Problem.** Line 1: n. Line 2: n values. Print the number of pairs i < j with gcd(a[i], a[j]) == 1. **Constraints:** 1 <= n <= 100000; 1 <= a[i] <= 1e6. **R versus W.** The graded wrong solution counts every pair sharing any common divisor >= 2.

Back to lesson: Final 2-B: Coprimality Census