Sum of all proper divisors from 1 to N | C ++ implementation to find sum of all proper divisor of numbers up to N ; Utility function to find sum of all proper divisor of number up to N ; Loop to find the proper divisor of every number from 1 to N ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int properDivisorSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; ++ i ) sum += ( n / i ) * i ; return sum - n * ( n + 1 ) / 2 ; } int main ( ) { int n = 4 ; cout << properDivisorSum ( n ) << endl ; n = 5 ; cout << properDivisorSum ( n ) << endl ; return 0 ; }