Foundations Working with digits and divisors
33. All Divisors of a Number
Given a positive integer n, return all of its divisors in increasing order.
A divisor of n is a positive integer that divides n with no remainder. So 1 and n are always
divisors of n, and 4 is a divisor of 12 because 12 = 4 × 3. List each divisor once.
Example 1
Input: n = 36
[1,2,3,4,6,9,12,18,36]Explanation: Each of these nine numbers divides 36 with no remainder. No other number from 1 to 36 does.
Example 2
Input: n = 1
[1]Explanation: 1 is the only divisor of 1. Here 1 and n are the same number, so it is listed once.
Example 3
Input: n = 9999999967
[1,9999999967]Explanation: No number between 1 and n divides this n, so the answer has just two values.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ n ≤ 1010
Clarifying questions
What you would ask an interviewer before writing any code.