TopcoderArchive
Archive
Algorithm problem

TheLuckyNumbersLevelOne

Problem statement, definition, constraints, and public examples.

Problem Statement

The digits 4 and 7 are lucky digits, and all other digits are unlucky. A first level lucky number is a positive integer whose decimal representation is a palindrome that contains only lucky digits. A palindrome is a number that reads the same forward and backward. John and Brus would like to count the number of first level lucky numbers within a specified range.

You are given longs a and b. Return the number of first level lucky numbers between a and b, inclusive.

Definition

Class:
TheLuckyNumbersLevelOne
Method:
find
Parameters:
long, long
Returns:
long
Method signature:
long find(long a, long b)
(be sure your method is public)

Constraints

  • a will be between 1 and 10^18, inclusive.
  • b will be between a and 10^18, inclusive.

Examples

  1. 1
    100
    Returns: 4
    The first level lucky numbers within this range are 4, 7, 44 and 77.
  2. 45
    54
    Returns: 0
    There are no first level lucky numbers here.
  3. 477444774
    477444774
    Returns: 1
    The given range contains only one integer and it is a first level lucky number.
  4. 456789123
    789123456
    Returns: 24
Back to all problems