TopcoderArchive
SRM26 Nov 2019
SRM 771

AllEven

Problem statement, definition, constraints, and public examples.

Problem Statement

A number is paired up if the number of occurrences of each digit is even. For example, 22, 4242, and 7720707727 are paired up, but 33033 and 12345 are not.

Given the longs lo and hi, count the paired up numbers in the closed interval [lo, hi].

Definition

Class:
AllEven
Method:
countInRange
Parameters:
long, long
Returns:
long
Method signature:
long countInRange(long lo, long hi)
(be sure your method is public)

Constraints

  • hi will be between 0 and 10^18 - 1, inclusive.
  • lo will be between 0 and hi, inclusive.

Examples

  1. 47
    999
    Returns: 5
    The five numbers are 55, 66, 77, 88, and 99.
  2. 47
    1010
    Returns: 7
    Compared to the previous example we now also gained 1001 and 1010.
  3. 12345678901
    98765432109
    Returns: 0
  4. 1234
    654321
    Returns: 6862
  5. 0
    10
    Returns: 0
    Note that zero is not a paired up number, as it has an odd number of zeros.
Back to all problems