Problem · Math
MediumIBM logoIBMFULLTIMEOA
See IBM hiring insights

Problem statement

Given positive integers n and p, list all positive factors of n in ascending order.

Return the factor at 1-based position p. If n has fewer than p factors, return 0.

Function

pthFactor(n: long, p: long) → long

Examples

Example 1

n = 20p = 3return = 4

The factors of 20 are [1, 2, 4, 5, 10, 20]. The third factor is 4.

Constraints

  • 1 ≤ n ≤ 10^15
  • 1 ≤ p ≤ 10^9

More IBM problems

drafts saved locally
public long pthFactor(long n, long p) {
    // Write your code here
}
n20
p3
expected4
checking account