TopCoder problem "AlmostPerfectNumber" used in TCCC07 Qual 2 (Division I Level One)



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.

 

Definition

    
Class:AlmostPerfectNumber
Method:count
Parameters:int, int, int
Returns:int
Method signature:int count(int left, int right, int k)
(be sure your method is public)
    
 

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

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7557

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10881&pm=7557

Writer:

andrewzta

Testers:

PabloGilberto , vorthys , Olexiy , ivan_metelsky

Problem categories:

Simple Math, Simple Search, Iteration