Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<cmath>
- #define long long long
- #define nln '\n'
- using namespace std;
- bool perfect_square(long n)
- {
- return (sqrt(n) == round(sqrt(n)));
- }
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- //freopen("demcapnghiem.inp", "r", stdin);
- // sau khi biến đổi, bài toán trở thành đếm ước của n+1
- long n;
- cin >> n;
- ++n; // cộng 1 vào n ở đây
- long ans = 0;
- for (long i = 1; i <= round(sqrt(n)); ++i)
- if (n % i == 0)
- ans += 2; // nếu thấy một số i mà n chia hết cho i thì cộng số lượng ước lên 2
- // Ví dụ: 6 : 3 = 2 mà 6 : 2 = 3
- cout << (perfect_square(n) ? ans-1 : ans) << nln;
- // dòng này có nghĩa nếu n là số chính phương thì phải giảm số lượng đi 1.
- // Ví dụ: 9 : 3 = 3 mà 9 : 3 = 3. Ta có 2 cặp (3, 3) (3, 3) giống nhau nên trừ đi 1 cặp
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment