Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

divisor summation

#include<iostream>
using namespace std;

int main() {

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


        int sum = 0;
        for (int i = 1; i * i <= n; i++) {
            if (n%i == 0) {
                sum += i;
                if (i != n/i) {
                    sum += n / i;
                }
            }
        }

        cout << sum - n << endl;
    }

		return 0;

}
Source by smart.ibsu.edu.ge #
 
PREVIOUS NEXT
Tagged: #divisor #summation
ADD COMMENT
Topic
Name
3+7 =