Description
Solutions
Pth Factor
📚RELATED PROBLEMS
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 foundlong int p
: the index of the factor to be returnedReturns
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}
. Using1-based
indexing, ifp = 3
, then4
is returned. ifp > 6
,0
would be returned.
Constraints:
1 <= n <= 1015
1 <= p <= 109
Related Problems
Testcase
Result
Case 1
input:
output: