Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether a Number Is Perfect

Basic Acceptance 78.12% Points 10.00

You are given a positive integer n. Your task is to determine whether it is a Perfect number. A number is perfect if it equals the sum of all its positive proper divisors, excluding the number itself.

Examples
Example 1

Input: n = 6
Output: Yes
Explanation: The proper divisors of 6 are 1, 2, and 3. Their sum is 1 + 2 + 3 = 6. Therefore, 6 is a Perfect number.

Example 2

Input: n = 28
Output: Yes
Explanation: The proper divisors of 28 are 1, 2, 4, 7, and 14. Their sum is 1 + 2 + 4 + 7 + 14 = 28. Therefore, 28 is a Perfect number.

Example 3

Input: n = 10
Output: No
Explanation: The proper divisors of 10 are 1, 2, and 5. Their sum is 1 + 2 + 5 = 8, which is not equal to 10.

Constraints
  • 1 <= n <= 109
Companies
Apple Qualcomm
Topics
Data Structures 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