Given a sequence a1, a2, ..., aN. Count the number of triples (i, j, k) such that 1 ≤ i < j < k ≤ N and GCD(ai, aj, ak) = 1. Here GCD stands for the Greatest Common Divisor.
Example : Let N=4 and array be :
1 2 3 4
Here answer is 4.
I want to calculate it if N is upto 10^5.
As noted in the comments, this doesn't answer the question at hand, but one that is perhaps closely enough related to give some ideas on how to proceed.
At https://projecteuler.chat/viewtopic.php?f=17&t=2889 Guego has written,
"It's quite easy to count the number $C(n)$ of triples $(a,b,c)$ with $1\leq a,b,c \leq n$ which are coprime ($\gcd(a,b,c)=1$).
"Indeed, using the formula $n^3 = \sum_d C(n/d)$, we can have $C(n)$ quite easily using a recursive algorithm, or with the Möbius inversion formula.
"I implemented it in python, and my program gives, for example, $$C(1000000) = 831907430687799769$$ in less than one second."
Guego later adds, "the sum is over all the possible values of $d$ (not just the divisors of $n$), but $n/d$ must be understood as an integer division."