Number of Common Factors - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
a = 12, b = 18
›
Output:
4
💡 Note:
Common factors are 1, 2, 3, and 6. Both 12 and 18 are divisible by each of these numbers.
Example 2 — Small Numbers
$
Input:
a = 25, b = 30
›
Output:
2
💡 Note:
Common factors are 1 and 5. GCD(25,30) = 5, and 5 has factors 1 and 5.
Example 3 — Coprime Numbers
$
Input:
a = 7, b = 13
›
Output:
1
💡 Note:
7 and 13 are prime numbers with no common factors except 1.
Constraints
- 1 ≤ a, b ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input
Two positive integers a=12, b=18
2
Process
Find all numbers that divide both evenly
3
Output
Count of common factors: 4
Key Takeaway
🎯 Key Insight: Common factors of two numbers are exactly the factors of their GCD
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code