number and index. Write out all divisors of number (the values d with number % d == 0) in ascending order and return the one at position index (counting from one).
If there are fewer than index divisors, return -1.
Trying every value up to number is the obvious way; try to get away with fewer steps.number=18, index=4 → 6
The divisors of 18 in ascending order are 1, 2, 3, 6, 9, 18. The fourth is 6.
number=13, index=3 → -1
13 is prime and has only two divisors, 1 and 13, so there is no third.
number=1, index=1 → 1
number=18, index=4
6
Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.