-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday16.cpp
More file actions
43 lines (34 loc) · 1.12 KB
/
day16.cpp
File metadata and controls
43 lines (34 loc) · 1.12 KB
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
42
43
#include <bits/stdc++.h>
using namespace std;
// SPOJ --- DIVSUM - Divisor Summation
/* Given a natural number n (1 <= n <= 500000), please output the summation of all its proper divisors.
Definition: A proper divisor of a natural number is the divisor that is strictly less than the number.
e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and the divisor summation is: 1 + 2 + 4 + 5 + 10 = 22.
Input
An integer stating the number of test cases (equal to about 200000), and that many lines follow, each containing one integer between 1 and 500000 inclusive.
Output
One integer each line: the divisor summation of the integer given respectively.*/
int main() {
int j,t,n;
cin>>t;
while(t--){
int sum=0;
cin>>n;
if(n==1){
cout<<0<<"\n";
}
else{
for(j=2;j<=sqrt(n);j++){
if(n%j==0){
if(j == n/j){
sum+=j;
}
else
sum = sum + j + n/j;
}
}
cout<<sum+1<<"\n";
}
}
return 0;
}