Previous Next
0 / 33
Module DEMO-32-60DEMO-C-32

Find Perfect Numbers in a Range

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself). For example, 6 is a perfect number because its divisors are 1, 2, and 3, and 1 + 2 + 3 = 6.

Task

Write a program that reads two integers A and B, and prints all perfect numbers in the range from A to B (inclusive), separated by spaces.

If there are no perfect numbers in the range, print nothing (just a blank line).

Constraints

You must use nested loops to solve this problem. The solution must work efficiently within the given range.

Input Format

A single line containing two integers A and B such that 1 <= A <= B <= 10000.

Output Format

A single line containing all perfect numbers in the range [A, B] separated by spaces. If there are no perfect numbers, output an empty line.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
1 100
6 28
Input: 1 100
Sample #2
Public sample
1 10000
6 28 496 8128
Input: 1 10000
Sample #3
Public sample
1 5
Input: 1 5
Sample #4
Public sample
8000 8200
8128
Input: 8000 8200

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings