Connection Status:
Competition Arena > AlmostPerfectNumber
TCCC07 Qual 2 · 2007-07-30 · by andrewzta · Simple Math, Simple Search, Iteration
Class Name: AlmostPerfectNumber
Return Type: int
Method Name: count
Arg Types: (int, int, int)
Problem Statement

Problem Statement

An integer x is called a proper divisor of an integer y if x is a divisor of y and 1 <= x < y.

Let us denote as s(a) the sum of all proper divisors of a. An integer a is called almost perfect by k if |a-s(a)| <= k.

You are given ints left, right and k. Return the number of integers between left and right, inclusive, that are almost perfect by k.

Constraints

  • left will be between 2 and 1000, inclusive.
  • right will be between left and 1000, inclusive.
  • k will be between 0 and 1000, inclusive.
Examples
0)
2
10
1
Returns: 4

The following numbers between 2 and 10 are almost perfect by 1: 2 (s(2) = 1), 4 (s(4) = 3), 6 (s(6) = 6) and 8 (s(8) = 7).

1)
5
5
5
Returns: 1
2)
11
20
50
Returns: 10
3)
2
1000
1
Returns: 12
4)
2
1000
2
Returns: 19

Submissions are judged against all 88 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class AlmostPerfectNumber with a public method int count(int left, int right, int k) · 88 test cases · 2 s / 256 MB per case

Submitting as anonymous