Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find the Number of Divisors of a Number

Basic Acceptance 87.65% Points 10.00

You are given a positive integer n. Your task is to return its total number of positive divisors, including 1 and n itself.

Examples
Example 1

Input: n = 12
Output: 6
Explanation: The positive divisors of 12 are 1, 2, 3, 4, 6, and 12. Therefore, the total number of divisors is 6.

Example 2

Input: n = 7
Output: 2
Explanation: Since 7 is prime, its only positive divisors are 1 and 7. Therefore, the count is 2.

Example 3

Input: n = 1
Output: 1
Explanation: The number 1 has exactly one positive divisor: 1.

Constraints
  • 1 = n = 10¹²
Companies
Apple eBay
Topics
Data Structures Basics Basics
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions