Pagini recente » Cod sursa (job #1461280) | Cod sursa (job #507784) | Cod sursa (job #877508) | Cod sursa (job #1512708) | Cod sursa (job #1799839)
#include<fstream>
#define DIM 100005
using namespace std;
int t, x, i, j, n;
int c[DIM], ok[DIM], nr[DIM];
long long d[DIM];
ifstream fin("sum.in");
ofstream fout("sum.out");
int main(){
n = 100000;
for(i = 2; i <= n; i++){
d[i] = (i + i) * 1LL * (i + i + 1) / 2;
ok[i] = 1;
}
for(i = 2; i <= n; i++){
if(c[i] == 0){
d[i] -= 3 * i;
for(j = i + i; j <= n; j += i){
c[j] = 1;
nr[j]++;
if(j % (i * i) == 0){
ok[j] = 0;
}
x = (j + j) / i;
d[j] -= x * 1LL * (x + 1) / 2 * i;
}
}
else{
if(ok[i] == 1){
for(j = i; j <= n; j += i){
x = (j + j) / i;
if(nr[i] % 2 == 1){
d[j] -= x * 1LL * (x + 1) / 2 * i;
}
else{
d[j] += x * 1LL * (x + 1) / 2 * i;
}
}
}
}
}
fin>> t;
for(; t; t--){
fin>> x;
fout<< d[x] <<"\n";
}
return 0;
}