Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find All Perfect Numbers in a Range

Basic Acceptance 82.42% Points 10.00

You are given two integers L and R. Your task is to print all Perfect numbers in the inclusive range [L, R] in ascending order, separated by spaces. A Perfect number equals the sum of all its positive proper divisors, excluding itself.

Examples
Example 1

Input: L = 1, R = 100
Output: 6 28
Explanation: The Perfect numbers in the range from 1 to 100 are 6 and 28.

Example 2

Input: L = 1, R = 1000
Output: 6 28 496
Explanation: The Perfect numbers in the range from 1 to 1000 are 6, 28, and 496.

Example 3

Input: L = 10, R = 20
Output: (empty)
Explanation: There are no Perfect numbers in this range, so there are no numbers to print.

Constraints
  • 1 <= L <= R <= 106
Companies
Samsung eBay DE Shaw
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