Advertisement
Dang_Quan_10_Tin

DIVISORS TS10 PTNK 2006-2007

Jan 15th, 2022 (edited)
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #define task "DIVISORS"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7.  
  8. using ll = long long;
  9. using ld = long double;
  10.  
  11. constexpr int N = 8 + 5;
  12. int n;
  13. int p[] = {2, 3, 5, 7, 11, 13, 17, 19}; // Danh sách số nguyên tố
  14. int t[N]; // Số mũ của các số nguyên tố trong danh sách trên
  15.  
  16. void Read()
  17. {
  18.     cin >> n;
  19. }
  20.  
  21. void Solve()
  22. {
  23.     // Phân tích thừa số nguyên tố
  24.     for (int i = 0; i < 8; ++i)
  25.         for (int j = 2; j <= n; ++j)
  26.         {
  27.             int v = j;
  28.             while (v % p[i] == 0)
  29.             {
  30.                 v /= p[i];
  31.                 ++t[i];
  32.             }
  33.         }
  34.  
  35.     ll ans(1);
  36.    
  37.     // Tính số ước của N!
  38.     for (int i = 0; i < 8; ++i)
  39.         ans = ans * (t[i] + 1);
  40.  
  41.     cout << ans - 1;
  42. }
  43.  
  44. int32_t main()
  45. {
  46.     ios::sync_with_stdio(0);
  47.     cin.tie(0);
  48.     cout.tie(0);
  49.     if (fopen(task ".INP", "r"))
  50.     {
  51.         freopen(task ".INP", "r", stdin);
  52.         freopen(task ".OUT", "w", stdout);
  53.     }
  54.  
  55.     Read();
  56.     Solve();
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement