You are viewing a single comment's thread. Return to all comments →
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; } };
Seems like cookies are disabled on this browser, please enable them to open this website
Day 19: Interfaces
You are viewing a single comment's thread. Return to all comments →
I added some optimisations(there is the half of operations if the number n is odd).
What do you think about it?