#include <iostream>
#include <cmath>
using namespace std;
const int N = 500001;
long long int sum[N];
int main()
{
long long int result = 0;
for(int i = 1; i <= N; i++)
{
result = 1;
int temp = i;
for(int j = 2; j * j <= temp; j++)
{
int num = 0;
while(temp % j == 0)
{
num++;
temp = temp / j;
}
if(num != 0)
result *= (pow(j, (num + 1)) - 1)/ (j - 1);
// refer http://mathschallenge.net/library/number/sum_of_divisors for logic
}
if(temp != 1)
{
result *= (temp + 1);
}
sum[i] = result;
}
int t, n;
cin >> t;
while(t--)
{
cin >> n;
cout << sum[n] - n << endl; // sum[n] - n for sum of proper divisor
}
return 0;
}
#include <cmath>
using namespace std;
const int N = 500001;
long long int sum[N];
int main()
{
long long int result = 0;
for(int i = 1; i <= N; i++)
{
result = 1;
int temp = i;
for(int j = 2; j * j <= temp; j++)
{
int num = 0;
while(temp % j == 0)
{
num++;
temp = temp / j;
}
if(num != 0)
result *= (pow(j, (num + 1)) - 1)/ (j - 1);
// refer http://mathschallenge.net/library/number/sum_of_divisors for logic
}
if(temp != 1)
{
result *= (temp + 1);
}
sum[i] = result;
}
int t, n;
cin >> t;
while(t--)
{
cin >> n;
cout << sum[n] - n << endl; // sum[n] - n for sum of proper divisor
}
return 0;
}
Comments
Post a Comment