How to find number of values x which achieve GCD(n, x) = 1
n is constant
x <= m
m can be bigger than n
the related problem to this question that I am trying to solve:
# | User | Rating |
---|---|---|
1 | jiangly | 3976 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3482 |
8 | hos.lyric | 3382 |
9 | gamegame | 3374 |
10 | heuristica | 3357 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | -is-this-fft- | 165 |
3 | Um_nik | 161 |
3 | atcoder_official | 161 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
7 | adamant | 154 |
8 | luogu_official | 152 |
9 | awoo | 151 |
10 | TheScrasse | 147 |
How to find number of values x which achieve GCD(n, x) = 1
n is constant
x <= m
m can be bigger than n
the related problem to this question that I am trying to solve:
Name |
---|
a number $$$x$$$ having $$$gcd(n, x) = 1$$$ means that it doesn't have any common prime factors with $$$n$$$ so we basically need to count numbers from 1 to m not having any common prime factors with $$$n$$$.
We can solve the reverse problem which is counting the numbers from 1 to m having at least one common prime factor with $$$n$$$.
To do so we need to factorise $$$n$$$ then use inclusion-exclusion principle to count such integers. Let the prime factors be $$$[p_1, p_2, ..., p_k]$$$, first we are going to count numbers from 1 to m having $$$p_1$$$ as a prime factor or $$$p_2$$$ or $$$p_3$$$ or ... etc but if a number has both $$$p_1$$$ and $$$p_2$$$ then it was counted twice so we need to subtract all numbers having any combination of these or any other combination of 2 prime factors but it can be noticed again that if a number has $$$p_1$$$, $$$p_2$$$ and $$$p_3$$$ then it is counted 3 times then subtracted 3 times so we didn't count it at all so we need to count and add the numbers having all 3 prime factors together $$$p_1$$$, $$$p_2$$$ and $$$p_3$$$ and any other combination of 3 prime factors then subtract the ones having combination of 4 prime factors and add the ones having combination of 5 prime factors etc for the same reason.
Thank you, your explanation is very good