#K43212. Counting Perfect Numbers

    ID: 27260 Type: Default 1000ms 256MiB

Counting Perfect Numbers

Counting Perfect Numbers

A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding the number itself). In mathematical terms, a number \(n\) is perfect if \(n = \sum_{d\mid n,\, d<n} d\). For example, 6 and 28 are perfect numbers because:

6 = 1 + 2 + 3

28 = 1 + 2 + 4 + 7 + 14

Your task is to process multiple test cases. For each test case, you are given an integer \(N\) and you need to count how many perfect numbers exist in the range \([1, N]\). Note that for \(N < 2\), the count is 0.

Use the input from standard input (stdin) and output the result for each test case to standard output (stdout), each answer on a new line.

inputFormat

The first line of input contains an integer \(T\) representing the number of test cases. Each of the next \(T\) lines contains a single integer \(N\), where \(N\) is the upper bound for counting perfect numbers.

Example:

4
6
28
100
500

outputFormat

For each test case, output the number of perfect numbers in the range \([1, N]\) on a separate line.

Example Output:

1
2
2
3
## sample
4
6
28
100
500
1

2 2 3

</p>