Submission #66
Details and source code
| ID | Time | User | Problem | Lang | Verdict |
|---|---|---|---|---|---|
| 66 | Jan 29, 2026, 10:40 AM | admin | Prime Divisor Spell | cpp | AC |
Source Code
cpp#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
int spf[MAXN+1];
void sieve(){
for (int i = 1; i <= MAXN; i++) spf[i] = i;
for (int i = 2; i * i <= MAXN; i++) {
if (spf[i] == i)
for (int j = i * i; j <= MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
sieve();
int T; cin >> T;
while(T--){
int n; cin >> n;
if(n == 1){
cout << -1 << "\n";
continue;
}
int sum = 0, last = -1;
while(n > 1){
int p = spf[n];
if(p != last){
sum += p;
last = p;
}
n /= p;
}
cout << sum << "\n";
}
return 0;
}