Editorial for UCLN với N
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
\(\color{red}{\text{Spoiler Alert}_{{}_{{}^{{}^{v2.0}}}}}\)
\(\color{red}{\text{Khuyến khích bạn đọc trước khi đọc phần lời giải xin hãy thử code ra thuật của mình dù nó có sai hay đúng}}\)
\(\color{red}{\text{Sau đó từ phần bài giải và thuật toán trước đó mà đối chiếu, rút nhận xét với thuật của mình và thu được bài học (không lãng phí thời gian đâu).}}\)
\(\color{orange}{\text{Hướng dẫn}}\)
- Duyệt \(i\) từ \(1\) đến \(N\), rồi tính \(gcd(i,N)\).
\(\color{goldenrod}{\text{Tiếp cận}}\)
- Nếu \(gcd(i,N) = p\) thì tăng số lượng.
C++int res = 0; for (int i = 1; i <= n; i++) if (__gcd(i,n) == p) res++; cout << res;
Comments