AlmostPerfectNumber
TCCC07 Qual 2 · 2007-07-30 · by andrewzta
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
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.
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).
5 5 5 Returns: 1
11 20 50 Returns: 10
2 1000 1 Returns: 12
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.
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