TopcoderArchiveVisit Topcoder
SRM28 Apr 2011
SRM 504.5

TheNumbersWithLuckyLastDigit

Problem statement, definition, constraints, and public examples.

Problem Statement

John believes that the digits 4 and 7 are lucky, and all other digits are unlucky. A positive integer is called a lucky number if its last digit is lucky. For example, 4, 14 and 207 are lucky numbers, while 40, 741 and 3 are not lucky numbers. John would like to represent the int n as a sum of only lucky numbers, and he would like to do this using the minimal possible number of summands. Return the number of summands in the representation, or -1 if it is impossible to achieve the goal.

Definition

Class:
TheNumbersWithLuckyLastDigit
Method:
find
Parameters:
int
Returns:
int
Method signature:
int find(int n)
(be sure your method is public)

Constraints

  • n will be between 1 and 1,000,000,000, inclusive.

Examples

  1. 99
    Returns: 4
    One of the possible representations is 99=14+24+27+34.
  2. 11
    Returns: 2
    11=4+7.
  3. 13
    Returns: -1
    It is impossible to achieve the goal.
  4. 1234567
    Returns: 1
Back to all problems