Connection Status:
Competition Arena > TheNumbersWithLuckyLastDigit
SRM 504.5 · 2011-04-28 · by Vasyl[alphacom] · Simple Math, Simple Search, Iteration
Class Name: TheNumbersWithLuckyLastDigit
Return Type: int
Method Name: find
Arg Types: (int)
Problem Statement

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.

Constraints

  • n will be between 1 and 1,000,000,000, inclusive.
Examples
0)
99
Returns: 4

One of the possible representations is 99=14+24+27+34.

1)
11
Returns: 2

11=4+7.

2)
13
Returns: -1

It is impossible to achieve the goal.

3)
1234567
Returns: 1
4)
1
Returns: -1

Submissions are judged against all 89 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TheNumbersWithLuckyLastDigit with a public method int find(int n) · 89 test cases · 2 s / 256 MB per case

Submitting as anonymous