I want to calculate the number of arrays of size $N$, such that for each of it's element $A_i, 1 \leq A_i \leq M$ holds, and gcd of elements of array is 1.
Constraints: $1 \leq A_i \leq M$ and $A_i$ should be integer.
For example: If $N=2$ and $M=2$. We will have
1 1
1 2
2 1
3 different arrays whose gcd are 1.
It is probably easiest to use inclusion/exclusion. If $M=1$, there is only one array of size $N$ and it has gcd of $1$. If $M=2$, there are $2^N$ arrays of size $N$, all but one of which have gcd of $1$. The one that fails is the array with $M=1$ with every element multiplied by $2$. Similarly, if $M=3$, there are $3^N$ arrays of size $N$, all but two of which have gcd of $1$. As $M$ grows, you get more deductions and need to worry about double counting the deductions. When $M=6$, for instance, there are $3^N$ arrays that have a common divisor of $2$, $2^N$ arrays that have a common divisor of $3$ and $1^N$ that have a common divisor of $5$ to avoid a gcd of $1$, but you have counted the array of all $6$'s in both the $2$ and $3$ cases, so the final value is $6^N-3^N-2^N-1^N+1^N$ Extending to large $M$, you get $$M^N-\sum_{{p \le M}_{\text{ p prime}}}\left \lfloor \frac Mp \right \rfloor^N+\sum_{{p,q \le M}_{p\neq q\text{ prime}}}\left \lfloor \frac M{pq}\right \rfloor^N-\dots$$