Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- #include <bitset>
- #include <algorithm>
- #define task "PRIMELCM"
- using namespace std;
- using ll = long long;
- using ld = long double;
- const int N = 1e7 + 1;
- const int M = 1e5 + 2;
- ll v[M], maxn, ans[M], st[M * 4];
- int n, id[M];
- bitset<N> ck;
- vector<int> pr;
- const ll mod = 998244353;
- ll Pow(ll a, ll b)
- {
- ll tmp = 1;
- for (; b > 0; b >>= 1)
- {
- if (b & 1)
- tmp = tmp * a % mod;
- a = a * a % mod;
- }
- return tmp;
- }
- void Read()
- {
- cin >> n;
- for (int i = 1; i <= n; ++i)
- {
- cin >> v[i];
- id[i] = i;
- maxn = max(maxn, (ll)sqrt((ld)v[i]));
- }
- for (int i = 2; i * i <= maxn; ++i)
- if (!ck[i])
- for (int j = i * i; j <= maxn; j += i)
- ck[j] = 1;
- for (int i = 2; i <= maxn; ++i)
- if (!ck[i])
- pr.push_back(i);
- }
- ll Cal(ll v)
- {
- ll ans = 1;
- for (auto i : pr)
- {
- ll n = v;
- if (n < (ll)i * i)
- break;
- int cnt = 0;
- while (n >= i)
- {
- n /= i;
- ++cnt;
- }
- if (cnt)
- ans = ans * Pow(i, cnt - 1) % mod;
- }
- return ans;
- }
- /* loga(b) = log2(b) / log2(a) */
- int loga(ll n, int k)
- {
- return log2((ld)n) / log2((ld)k);
- }
- void Push(int id)
- {
- st[id << 1] = st[id << 1] * st[id] % mod;
- st[id << 1 | 1] = st[id << 1 | 1] * st[id] % mod;
- st[id] = 1;
- }
- void upd(int id, int l, int r, int &a, int &b, int &v)
- {
- if (l > b || r < a)
- return;
- if (l >= a && r <= b)
- {
- st[id] = st[id] * v % mod;
- return;
- }
- Push(id);
- upd(id << 1, l, (l + r) / 2, a, b, v);
- upd(id << 1 | 1, (l + r) / 2 + 1, r, a, b, v);
- }
- ll Get(int id, int l, int r, int pos)
- {
- if (l == r && r == pos)
- return st[id];
- Push(id);
- if ((l + r) / 2 >= pos)
- return Get(id << 1, l, (l + r) / 2, pos);
- return Get(id << 1 | 1, (l + r) / 2 + 1, r, pos);
- }
- void Solve()
- {
- fill_n(st, M * 4, 1);
- sort(id + 1, id + n + 1, [&](int &x, int &y) {
- return v[x] < v[y];
- });
- for (auto i : pr)
- {
- ll cur = i;
- int tmp = loga(v[id[n]], i);
- for (int j = 2; j <= tmp; ++j)
- {
- cur = cur * i;
- int l = 1, m, h = n;
- while (l <= h)
- {
- m = (l + h) / 2;
- if (v[id[m]] < cur)
- l = m + 1;
- else
- h = m - 1;
- }
- upd(1, 1, n, l, n, i);
- }
- }
- for (int i = 1; i <= n; ++i)
- ans[id[i]] = Get(1, 1, n, i);
- for (int i = 1; i <= n; ++i)
- cout << ans[i] << " ";
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- freopen(task ".INP", "r", stdin),
- freopen(task ".OUT", "w", stdout);
- Read();
- Solve();
- }
Add Comment
Please, Sign In to add comment