C++#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
mt19937_64 eng(time(0) ^ clock());
template<typename T>
T rnd(T l, T r) { return eng() % (r - l + 1) + l; }
int pC, pri[250005];
bool vis[250005];
vector<int> d[250005];
void Init(int n) {
for (int i = 2; i <= n; i++) {
if (!vis[i])
pri[++pC] = i;
for (int j = 1; j <= pC && i * pri[j] <= n; ++j) {
vis[i * pri[j]] = 1;
if (i % pri[j] == 0)
break;
}
}
for (int i = 1; i <= pC && pri[i] <= n; i++)
for (int j = pri[i]; j <= n; j += pri[i])
d[j].emplace_back(i);
memset(vis, 0, sizeof(vis));
}
const int B = 300, P = 998244353;
int n, m;
int bel[250005], L[250005], R[250005], g[250005], re[250005], to[250005];
ll a[250005], sum[250005], laz[250005];
set<int> s[250005];
int tpt, stkt[250005];
int tp, stk[250005];
void Calc(int i) {
int x = i;
sum[i] = 0;
while (x <= R[bel[i]]) {
(sum[i] += a[x]) %= P;
// if (i == 2)
// cout << "/ " << x << " " << a[x] << "\n";
x += g[x];
// cout << i << " " << x << "\n";
}
to[i] = x;
}
bool arv[250005];
void Update(int x) {
for (int i = R[x]; i >= L[x]; i--) {
sum[i] = a[i] % P;
if (i + g[i] <= R[x]) {
// cout << i << " " << i + g[i] << "\n";
(sum[i] += sum[i + g[i]]) %= P, to[i] = to[i + g[i]];
} else {
to[i] = i + g[i];
}
}
}
void Modify(int l, int r, ll c) {
int x = bel[l], y = bel[r];
int now = c;
for (int i : d[c]) {
// cerr << pri[i] << "\n";
int cnt = 0;
while (now % pri[i] == 0)
now /= pri[i], cnt++;
if ((int) s[i].size() == 0)
continue;
auto pl = s[i].lower_bound(l);
auto pr = s[i].lower_bound(r + 1);
for (auto it = pl; it != pr; it++) {
int p = *it, tmp = cnt;
while (re[p] % pri[i] == 0 && tmp > 0)
re[p] /= pri[i], g[p] *= pri[i], tmp--;
if (re[p] % pri[i])
stkt[++tpt] = p;
if (!vis[p])
stk[++tp] = p, vis[p] = 1;//, cout << "? " << p << "\n";
}
while (tpt)
s[i].erase(stkt[tpt--]);
}
for (int i = 1; i <= tp; i++) {
Calc(stk[i]);
Update(bel[stk[i]]);
// cout << "? " << stk[i] << " " << to[stk[i]] << "\n";
}
// printf("%lld%c", a[i] * laz[bel[i]] % P, " \n"[i == n]);
for (int i = 1; i <= tp; i++)
vis[stk[i]] = 0;
tp = 0;
if (x == y) {
for (int i = l; i <= r; i++)
a[i] = a[i] * c % P;
Update(x);
} else {
// cout << "?!\n";
for (int i = l; i <= R[x]; i++)
a[i] = a[i] * c % P;
for (int i = L[y]; i <= r; i++)
a[i] = a[i] * c % P;
Update(x), Update(y);
for (int i = x + 1; i < y; i++)
laz[i] = laz[i] * c % P;
}
}
int main() {
scanf("%d%d", &n, &m);
Init(250000);
for (int i = 1; i <= n; i++)
scanf("%lld", a + i);
for (int i = 1; i <= n; i++)
bel[i] = (i - 1) / B + 1;
for (int i = 1; i <= bel[n]; i++)
L[i] = (i - 1) * B + 1, R[i] = min(n, i * B);
for (int i = 1; i <= bel[n]; i++)
laz[i] = 1;
for (int i = 1; i <= n; i++) {
g[i] = __gcd((ll) i, a[i]);
re[i] = i / g[i];
for (int j : d[re[i]])
s[j].emplace(i);//, cout << "? " << pri[j] << " " << i << "\n";
}
for (int i = 1; i <= n; i++)
Calc(i);
// for (int i = 1; i <= n; i++)
// printf("%d%c", to[i], " \n"[i == n]);
for (int _ = 1, op, x, y, z; _ <= m; _++) {
scanf("%d%d", &op, &x);
if (op == 1) {
scanf("%d%d", &y, &z);
Modify(x, y, z);
// for (int i = 1; i <= n; i++)
// printf("%lld%c", a[i], " \n"[i == n]);
// for (int i = 1; i <= n; i++)
// printf("%d%c", to[i], " \n"[i == n]);
} else {
ll ans = 0;
for (int i = x; i <= n; i = to[i]) {
// cout << i << " " << to[i] << " " << sum[i] << " " << laz[bel[i]] << "\n";
(ans += sum[i] * laz[bel[i]] % P) %= P;
}
printf("%lld\n", ans);
}
}
return 0;
}
C++#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m, V1, V2;
int main() {
n = 250000, m = 250000, V1 = 998244352, V2 = 2.5e5;
cout << n << " " << m << "\n";
for (int i = 1; i <= n; i++)
cout << rng() % V1 << " \n"[i == n];
while (m--) {
int op = rng() & 1;
if (op) {
cout << 2 << " " << rng() % n + 1 << "\n";
} else {
int l = rng() % n + 1, r = rng() % n + 1;
if (l > r)
swap(l, r);
cout << 1 << " " << l << " " << r << " " << rng() % V2 + 1 << "\n";
}
}
return 0;
}
C++#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[100001],g[100001],Mod=998244353;
signed main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i],g[i]=__gcd(a[i],i);
while(m--)
{
int op;
cin>>op;
if(op==1)
{
int l,r,c;
cin>>l>>r>>c;
for(int i=l;i<=r;i++)
(a[i]*=c)%=Mod,g[i]=__gcd(g[i]*c,i);
}
else
{
int x;
cin>>x;
int ans=0;
while(x<=n)
{
(ans+=a[x])%=Mod;
x+=g[x];
}
cout<<ans<<"\n";
}
}
}