TopCoder problem "CoolNumber" used in TCHS SRM 36 (Division I Level Three)



Problem Statement

    Let's call a given number cool if its digits can be divided into two sets such that the sum of the digits in one set is equal to the sum of the digits in the other set. For example, the number 242 is cool because we can divide it into sets {2, 2} and {4}, and the sum of the digits in each set is 4. Given two ints A and B, return how many numbers between A and B, inclusive, are cool.
 

Definition

    
Class:CoolNumber
Method:count
Parameters:int, int
Returns:int
Method signature:int count(int A, int B)
(be sure your method is public)
    
 

Constraints

-A will be between 1 and 109, inclusive.
-B will be between A and 109, inclusive.
-The difference between B and A will be at most 106.
 

Examples

0)
    
1
50
Returns: 4
Here we've got following cool numbers: 11, 22, 33, 44.
1)
    
1
1000
Returns: 135
2)
    
6354
234363
Returns: 82340

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10774&pm=7994

Writer:

mateuszek

Testers:

PabloGilberto , brett1479 , Olexiy , ivan_metelsky

Problem categories:

Brute Force, Recursion, Simple Search, Iteration