Number of Common Factors

Given two positive integers a and b, return the number of common factors of a and b.

An integer x is a common factor of a and b if x divides both a and b.

Example 1
Inputa = 12, b = 6
Output4
The common factors of 12 and 6 are 1, 2, 3, and 6.
Example 2
Inputa = 25, b = 30
Output2
The common factors of 25 and 30 are 1 and 5.

Constraints

  • 1 <= a, b <= 1000

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate