Advertisement
Dang_Quan_10_Tin

MAHOA TS10 PTNK 2012-2013

Jan 15th, 2022
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #define task "MAHOA"
  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 = 1e6 + 5;
  12. int n, cnt[N];
  13.  
  14. void Read()
  15. {
  16.     cin >> n;
  17. }
  18.  
  19. void Solve()
  20. {
  21.     // Sàng nguyên tố Eratosthenes
  22.     for (int i = 2; i <= n; ++i)
  23.         if (cnt[i] == 0)
  24.             for (int j = i; j <= n; j += i)
  25.                 ++cnt[j];
  26.  
  27.     pair<int, int> ans = {0, 0};
  28.  
  29.     for (int i = n; i; --i)
  30.         ans = max(ans, make_pair(cnt[i], i));
  31.  
  32.     cout << ans.second;
  33. }
  34.  
  35. int32_t main()
  36. {
  37.     ios::sync_with_stdio(0);
  38.     cin.tie(0);
  39.     cout.tie(0);
  40.     if (fopen(task ".INP", "r"))
  41.     {
  42.         freopen(task ".INP", "r", stdin);
  43.         freopen(task ".OUT", "w", stdout);
  44.     }
  45.  
  46.     Read();
  47.     Solve();
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement