Answer: SERVIFY Hiring | Number of Common Factors | Off-Campus OA (2023)

Answer · Posted Jun 2026

Approach A number that divides both a and b must also divide their Greatest Common Divisor (GCD). Therefore: Find gcd(a, b). Count the number of divisors of the GCD. Return the count. To count divisors efficiently: Iterate from 1 to √gcd. If i divides gcd: Count i. Count gcd / i if it is different from i. Strategy Compute gcd(a, b) using Euclid's Algorithm. Traverse all integers from 1 to √gcd. For every divisor found: Add 1 for the divisor. ...

The full answer & interview discussion are available to premium members.

Log in Create a free account