2427. Number of Common Factors

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2427

class Solution:
    def commonFactors(self, a: int, b: int) -> int:
        g = gcd(a, b)
        res, x = 0, 1
        while x * x <= g:
            if g % x == 0:
                res += 1
                res += x * x < g
            x += 1
        return res