We can calculate the number of integers between $1$ and a given integer n that are relatively prime to n, using Euler function:
Let $p_1^{\varepsilon1}\cdot p_2^{\varepsilon2} \cdots p_k^{\varepsilon k}$ be the prime factorization of n. Then $\phi(n)=n\cdot\frac{p_1-1}{p_1}\cdot\frac{p_2-1}{p_2}\cdots\frac{p_k-1}{p_k} $
But why stop here? My question is:
Is there a fast algorithm to calculate the number of integers between two integers that are relatively prime to a given integer?
According to A059956, The probability that two integers x and x+y picked at random are relatively prime is $1/\zeta{(2)}$ .
Can I estimate the answer to be: $$\frac{y}{\zeta{(2)}}=\frac{6y}{\pi^2}$$
Is there a better method that can give me a more accurate answer to my question?
Determine the prime factors of the given number and for every such prime, scratch the numbers in the interval being divisble by that prime.
If the interval is small enough such that the numbers can be stored in an array, the calculation can be speed up drastically because it is sufficient to start with the first number in the interval being divisble by a prime and then adding the prime until we reach a number greater than the end of the interval.
If the intervall is too large, brute force seems to be the only way.
By the way, the gcd-calculation can already be realized very efficiently.