Spoj DIVSUM Solution

#include<bits/stdc++.h>
#define N 500000
using namespace std;

int divisor[N+1];
void Count()
{
for(int i=1;i<=N;i++)
{
for(int j=i;j<=N;j+=i)
divisor[j] += i;
}
}

int main()
{
Count();
int t;
cin >> t;

while(t--)
{
int n;
cin >> n;

cout << divisor[n] - n << "\n";
}

return 0;
}

Comments