// Arup Guha
// 11/13/2023
// CIS 3362 Quiz 4 Problem 7 Solution

#include <stdio.h>

long long sumDivisors(long long n) {

    long long res = 0;

    // Just go to square root. This is key for time savings.
    for (long long i=1; i*i<=n; i++) {

        // We only want to add if we find something divisible.
        if (n%i == 0) {

            // This makes sense.
            res += i;

            // This is key - add the "flip" divisor as long as it's unique.
            if (n/i > i)
                res += n/i;
        }
    }

    return res;

}

int main() {

    // Basic tests.
    for (int i=2; i<=100; i++)
        printf("%d %lld\n", i, sumDivisors(i));

    // For run time.
    printf("%lld\n", sumDivisors(1000000000000LL));
    return 0;

}
