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!

Create an Account

Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.

Create account

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 May 2026

Contest runs May 1 - 31. Complete challenges to climb the leaderboard!

Points are calculated for challenges completed during the contest period.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In