EasyFoundational
Count the Positive Divisors of a Number
- Time limit
- 1 s
- Memory limit
- 128 MB
- Estimated
- 15 min
- GCD and Divisibility
Description
Given a positive integer n, return the number of its positive divisors.
A positive divisor is an integer greater than zero that divides n exactly, leaving no remainder. Count each divisor once.
For example, the positive divisors of 12 are 1, 2, 3, 4, 6, and 12, so the answer is 6. Every positive integer has at least two divisors only when it is greater than 1; the number 1 has exactly one positive divisor.
Implement countDivisors(n).
Constraints
1 <= n <= 1000000
Sample cases
3Sample 1
Input
n = 12
Expected output
6
Sample 2
Input
n = 1
Expected output
1
Sample 3
Skills and languages
Concepts
- Divisibility and Remainders
Languages
- Python 3
Solve this problem
Create a free account to write, run and submit your solution.
- Write Python or Java in the browser, with your draft saved as you type
- Run your code on the examples as often as you like
- Submit to a sandboxed judge and see exactly which case failed
- Ask the AI mentor for a hint without being handed the answer