Skip to content

Instantly share code, notes, and snippets.

@OmarJH
Created May 2, 2015 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OmarJH/1370ffd4721f9ef9404e to your computer and use it in GitHub Desktop.
Save OmarJH/1370ffd4721f9ef9404e to your computer and use it in GitHub Desktop.
ACM - DIVSUM - Divisor Summation - SPOJ
#include <iostream>
#include <string>
using namespace std;
int calcpr(int n)
{
if (n == 1)
return 0;
int summ = 0;
for (int i = 1; i*i <= n; i++)
{
if (n%i == 0)
{
summ = summ + i ;
if (i != 1)
{
if (n / i == i)
break;
summ += n / i;
}
}
}
return summ;
}
int main()
{
int t, x;
cin >> t;
while (t--)
{
cin >> x ;
cout << calcpr(x) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment