-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUMDIV.cpp
41 lines (32 loc) · 813 Bytes
/
SUMDIV.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
using namespace std;
long long calculateSumDivisors(long long number);
int main()
{
int numberOfTestCases;
cin >> numberOfTestCases;
while (numberOfTestCases--)
{
long long number;
cin >> number;
long long sumDivisors = calculateSumDivisors(number);
cout << sumDivisors << endl;
}
}
long long calculateSumDivisors(long long dividend)
{
long long sumDivisors = 0;
for (long long divisor = 1; (divisor * divisor) <= dividend; divisor++)
{
if (dividend % divisor == 0)
{
sumDivisors += divisor;
long long quotient = dividend / divisor;
if (quotient != divisor)
{
sumDivisors += quotient;
}
}
}
return sumDivisors;
}