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:
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:
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 163 |
4 | TheScrasse | 159 |
5 | nor | 157 |
6 | maroonrk | 155 |
7 | -is-this-fft- | 152 |
8 | Petr | 146 |
8 | orz | 146 |
10 | BledDest | 145 |
Название |
---|
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