Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ul unsigned long long
- #define ld long double
- #define iv(v) for(auto &i:v) cin >> i;
- #define ov(v) for(auto &i:v) cout << i << " ";
- #define Bismillah ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- using namespace std;
- int main() {
- Bismillah
- ll n;
- cin >> n;
- vector<ll>v(n);
- iv(v)
- map<ll,ll>m;
- for (ll i=0; i<n; i++) {
- for (ll j=1; j*j<=v[i]; j++) {
- if (v[i]%j==0) {
- m[j]++;
- if (v[i]!=j*j) m[v[i]/j]++;
- }
- }
- }
- // unordered_map<ll,ll>a;
- vector<ll>a(n+1);
- for (auto i:m) {
- a[i.second]=max(a[i.second],i.first);
- }
- ll pre=1;
- vector<ll>ans;
- for (ll i=n; i>0; i--) {
- pre=max(pre,a[i]);
- ans.push_back(pre);
- }
- // 5
- // 2 4 3 4 6
- reverse(ans.begin(), ans.end());
- ov(ans)
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment