Untitled
user_7653193
c_cpp
a year ago
2.2 kB
15
Indexable
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define II pair<int, int>
#define fs first
#define sc second
#define endl '\n'
#define mp(x, y) make_pair(x, y)
#define sz(x) ((int) (x.size()))
#define forlr(i, l, r) for(int i = l; i <= r; ++i)
#define forrl(i, r, l) for(int i = r; i >= l; --i)
#define show(v) for(auto i : v) cout << i << " "; cout << endl;
#define showlr(v, l, r) for (int i = l; i <= r; i++) cout << v[i] << " "; cout << endl;
#define all(v) v.begin(), v.end()
#define Unique(v) v.erase(unique(all(v)), v.end());
const long long LINF = 1ll << 60;
const int INF = 1 << 30;
const int N = 1e6 + 10;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bool last_subtask;
int q, n = 1000008;
int a[N], ans[N];
int cnt[N];
void Sub123() {
forlr(i, 1, n) {
for(int j = i; j <= n; j += i) cnt[j] += i;
}
forlr(i, 1, q) cout << cnt[a[i]] << " ";
cout << endl;
}
bool nonPrime[N];
void Sub4() {
int L = a[1], R = a[q];
nonPrime[2] = false;
for(int i = 4; i <= n; i += 2) nonPrime[i] = true;
for(int i = 3; i <= n; i += 2) {
if(!nonPrime[i]) {
for(int j = i * i; j <= n; j += i) {
nonPrime[j] = true;
}
}
}
forlr(prime, 2, n) {
if(nonPrime[prime]) continue;
for(int j = ((L + prime - 1) / prime) * prime; j <= R; j += prime) {
int x = a[j - L + 1], cp = 1;
while(x % prime == 0) x /= prime, cp *= prime;
ans[j - L + 1] *= (cp * prime - 1) / (prime - 1);
a[j - L + 1] = x;
}
}
forlr(i, 1, q) {
if(a[i] != 1) ans[i] *= a[i] + 1;
cout << ans[i] << " ";
}
cout << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> q;
last_subtask = true;
forlr(i, 1, q) {
cin >> a[i];
ans[i] = 1;
if(i > 1 && a[i] != a[i - 1] + 1) last_subtask = false;
}
if(!last_subtask) Sub123();
else Sub4();
return 0;
}
Editor is loading...
Leave a Comment