Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

Problems > Sum of Pairwise GCDs > Editorial

Sum of Pairwise GCDs — Solution & Editorial

Back to the Problem

For each d, count pairs whose gcd is a MULTIPLE of d = C(cnt-multiples, 2), then recover pairs with gcd EXACTLY d by a downward subtractive sieve; sum d·exact[d].

Complexity: O(V log V + N)

Watch out: The answer reaches ~105·C(N,2) ≈ 5×1014.