Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find the Sum of Divisors

Basic Acceptance 78.12% Points 10.00

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

Examples
Example 1

Input: n = 6
Output: 12
Explanation: The positive divisors of 6 are 1, 2, 3, and 6. Their sum is 1 + 2 + 3 + 6 = 12.

Example 2

Input: n = 7
Output: 8
Explanation: Since 7 is prime, its positive divisors are 1 and 7. Their sum is 1 + 7 = 8.

Example 3

Input: n = 1
Output: 1
Explanation: The number 1 has only one positive divisor, 1. Therefore, the sum is 1.

Constraints
  • 1 = n = 10¹²
Companies
Samsung Flipkart ZScaler
Topics
Data Structures Basics Hash Table
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