Check for perfect number

Beginner Problems Basic Maths Easy
  • This simple mathematical concept is often used in error detection and correction algorithms in software development
  • In particular, it is used during checksum techniques where data is divided into equal parts
  • The sum of these parts should add up to a predefined value (a perfect number in some cases)
  • If the sum isn't a perfect number, it indicates that an error has occurred during data transmission, allowing developers to detect and correct errors
  • These are especially useful in network communications and data storage systems which require high reliability

You are given an integer n. You need to check if the number is a perfect number or not. Return true if it is a perfect number, otherwise, return false.


A perfect number is a number whose proper divisors add up to the number itself.

Examples:

Input: n = 6

Output: true

Explanation: Proper divisors of 6 are 1, 2, 3.

1 + 2 + 3 = 6.

Input: n = 4

Output: false

Explanation: Proper divisors of 4 are 1, 2.

1 + 2 = 3.

Input: n = 28

Constraints

  • 1 <= n <= 5000

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree