You are viewing a single comment's thread. Return to all comments →
efficient solution in python3:(thanks to @RodneyShag https://www.hackerrank.com/RodneyShag) (detail solution => https://www.hackerrank.com/challenges/30-interfaces/forum/comments/258725)
time complexity of this solution is O(sqrt(n)) space complexity is O(1)
import math class Calculator(AdvancedArithmetic): def divisorSum(self, n): sqrt = round(math.sqrt(n)) divisors_sum = 0 for i in range(1, sqrt+1): if n % i == 0: divisors_sum += i + n/i if (sqrt * sqrt == n): divisors_sum -= sqrt return int(divisors_sum)
Day 19: Interfaces
You are viewing a single comment's thread. Return to all comments →
efficient solution in python3:(thanks to @RodneyShag https://www.hackerrank.com/RodneyShag) (detail solution => https://www.hackerrank.com/challenges/30-interfaces/forum/comments/258725)
time complexity of this solution is O(sqrt(n)) space complexity is O(1)