Description
Solutions
Submission
Pth Factor

Determine the factors of a number (i.e., all positive integer values that evenly divide into a number) and then return the pth element of the list, sorted ascending. If there is no pth element, return 0.

Function Description

Complete the function pthFactor in the editor.

pthFactor has the following parameter(s):

  • long int n: the integer whose factors are to be found
  • long int p: the index of the factor to be returned
  • Returns

    long int: the value of the pth integer factor of n or, if there is no factor at that index, then 0 is returned.

    Example 1:

    Input:  n = 20, p = 3
    Output: 0
    Explanation:

    The factor of 20 in ascending order are {1, 2, 4, 5, 10, 20}. Using 1-based indexing, if p = 3, then 4 is returned. if p > 6, 0 would be returned.

    Constraints:
    • 1 <= n <= 1015
    • 1 <= p <= 109
    Testcase

    Result
    Case 1

    input:

    output: