Coprime triples
Time limit2sMemory limit512 MB
Count index triples i < j < k whose three values have gcd 1, with values up to 10^6 and n up to 10^5.
- Level
Medium7 of 10
- Topics
- Number theory, Combinatorics, Math, Dynamic programming
- Solved
- No attempts yet
Problem
You are given a sequence of length .
Write a program that counts the triples with and , where is the greatest common divisor.
The same value may appear several times, and triples are distinguished by their indices, not by their values.
Input
The first line contains the length ().
The second line contains (), separated by spaces.
Output
Print the number of triples that satisfy the condition on the first line.