• + 1 comment

    I added some optimisations(there is the half of operations if the number n is odd).

    What do you think about it?

    class Calculator : public AdvancedArithmetic {
    public:
        int divisorSum(int n) {
            int sum = n + 1;
            const int s = sqrt(n);
            const int di = 1 + (n & 1);
    
            for(int i = di + 1; i <= s; i += di) {
                if (n % i == 0) {
                    sum += i + n / i;
                }
            }
    
            if (s * s == n) sum -= s;
            return sum;
        }
    };