COOLNUMS - Cool Numbers

Cool numbers are those, whose digits can be partitioned into two sets such that the sum of the digits in either sets are equal.
Example: 23450 is cool because 3+4+0 = 2+5; So is 91125;
The numbers 567, 34523 are not cool, since there is no such digit partition.

Write a program that prints the number of cool numbers in the inclusive range [A,B].


Input Format:
The input file consists of multiple testcases.
Each case contains one line containing two 32-bit unsigned integers A and B. (1 <= A <= B <= 4*109).
Input terminates with a line containing two zeros and must not be processed.

Output Format:
For each testcase print a single line containing one integer saying the number of cool numbers between A and B, inclusive.

Sample Input:
1 11
12 20
1 20
3 100
6354 234363
123456789 234567891
0 0
Sample Output:
1
0
1
9
82340
54801678

Test Data:
About 50 testcases.


Added by:Prasanna
Date:2007-10-08
Time limit:5.673s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ADA95 ASM32 BASH BF C CSHARP CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN HASK ICON ICK JAVA LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST TEXT WHITESPACE
Resource:NITT ACM ICPC Local Contest 2007 [Topcoder problem with Constraints raised]

hide comments
2011-10-21 10:13:14 Shubham Agarwalla
shubham.agarwalla@tcs.com
2011-10-21 10:12:57 Shubham Agarwalla
solution in java needed
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.