Leetcode 1284 Solution

This article provides solution to leetcode question 1284 (four-divisors)

https://leetcode.com/problems/four-divisors

Solution

class Solution:
    def sumFourDivisors(self, nums: List[int]) -> int:
        ans = 0

        for num in nums:
            s = 1 + num

            ele = 2
            cnt = 0
            while ele * ele < num and cnt <= 1:
                if num % ele == 0:
                    cnt += 1
                    s += ele + num // ele
                ele += 1

            if cnt == 1 and ele * ele != num:
                ans += s

        return ans