lina_os

Untitled

May 12th, 2025
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ll long long
  4. #define ul unsigned long long
  5. #define ld long double
  6. #define iv(v) for(auto &i:v) cin >> i;
  7. #define ov(v) for(auto &i:v) cout << i << " ";
  8. #define Bismillah ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  9.  
  10. using namespace std;
  11.  
  12. int main() {
  13.     Bismillah
  14.     ll n;
  15.     cin >> n;
  16.     vector<ll>v(n);
  17.     iv(v)
  18.     map<ll,ll>m;
  19.     for (ll i=0; i<n; i++) {
  20.         for (ll j=1; j*j<=v[i]; j++) {
  21.             if (v[i]%j==0) {
  22.                 m[j]++;
  23.                 if (v[i]!=j*j) m[v[i]/j]++;
  24.             }
  25.         }
  26.     }
  27. //    unordered_map<ll,ll>a;
  28.     vector<ll>a(n+1);
  29.     for (auto i:m) {
  30.         a[i.second]=max(a[i.second],i.first);
  31.     }
  32.     ll pre=1;
  33.     vector<ll>ans;
  34.  
  35.     for (ll i=n; i>0; i--) {
  36.         pre=max(pre,a[i]);
  37.         ans.push_back(pre);
  38.     }
  39. //    5
  40. //    2 4 3 4 6
  41.     reverse(ans.begin(), ans.end());
  42.     ov(ans)
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment