TopcoderArchive
Archive
Algorithm problem

TheYetAnotherLuckyNumbersProblem

Problem statement, definition, constraints, and public examples.

Problem Statement

John and Brus believe that the digits 4 and 7 are lucky and all others are not. According to them, a lucky number is a number that contains only lucky digits in its decimal representation.

You are given longs A, B and C. Return the number of integers between A and B, inclusive, that can be represented as a sum of up to C lucky numbers.

Definition

Class:
TheYetAnotherLuckyNumbersProblem
Method:
find
Parameters:
long, long, long
Returns:
long
Method signature:
long find(long A, long B, long C)
(be sure your method is public)

Constraints

  • A will be between 1 and 474747474747474747, inclusive.
  • B will be between A and 474747474747474747, inclusive.
  • C will be between 1 and 7, inclusive.

Examples

  1. 1
    12
    2
    Returns: 4
    There are four numbers on this interval that are either lucky or can be represented as a sum of two lucky numbers: 4, 7, 8 = 4+4 and 11 = 4+7.
  2. 1
    12
    3
    Returns: 5
    The same numbers from the previous case and the nubmer 12 = 4+4+4.
  3. 4777778
    7444443
    1
    Returns: 0
    No lucky numbers on this interval.
  4. 1234567
    9876543210
    7
    Returns: 6999664461
Back to all problems