Count the number of positive divisors (also called factors) of a given positive integer. A divisor is a positive integer that divides the number evenly with no remainder. For example, the divisors of 12 are 1, 2, 3, 4, 6, and 12, so the count is 6. Return 0 for null input or for numbers that are zero or negative.
Examples:
Input: num = 12
Output: 6
Explanation: The divisors of 12 are 1, 2, 3, 4, 6, 12
Input: num = 7
Output: 2
Explanation: 7 is prime, so its only divisors are 1 and 7
Input: num = 1
Output: 1
Explanation: The only divisor of 1 is 1 itself
Input: num = 0
Output: 0
Explanation: Zero and negative numbers do not have positive divisors
Input: num = null
Output: 0
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay August 2026
Contest runs August 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.