Connection Status:
Competition Arena > FortunateNumbers
SRM 515 · 2011-05-25 · by lyrically · Simple Search, Iteration
Class Name: FortunateNumbers
Return Type: int
Method Name: getFortunate
Arg Types: (vector<int>, vector<int>, vector<int>)
Problem Statement

Problem Statement

Lecette thinks that 5 and 8 are fortunate digits. A positive integer is called a fortunate number if it has only fortunate digits in its decimal representation.

You are given three int[]s a, b and c. Return that number of fortunate numbers which can be expressed as a[i] + b[j] + c[k] for some indices i, j and k. Note that you must not count the same fortunate number more than once.

Constraints

  • a, b and c will each contain between 1 and 50 elements, inclusive.
  • Each element of a, b and c will be between 1 and 30,000, inclusive.
Examples
0)
{ 1, 10, 100 }
{ 3, 53 }
{ 4, 54 }
Returns: 2

We have two fortunate numbers 8 = 1 + 3 + 4 and 58 = 1 + 3 + 54. 58 can be also expressed as 1 + 53 + 4, but you must not count 58 twice.

1)
{ 47 }
{ 500 }
{ 33 }
Returns: 0

580 is not a fortunate number.

2)
{ 100, 1, 10, 100, 1, 1 }
{ 3, 53, 53, 53, 53, 53, 53 }
{ 4, 54, 4, 54, 4, 54 }
Returns: 2
3)
{ 500, 800 }
{ 50, 80 }
{ 5, 8 }
Returns: 8
4)
{ 30000, 26264 }
{ 30000, 29294 }
{ 30000, 29594 }
Returns: 3

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

Coding Area

Language: C++17 · define a public class FortunateNumbers with a public method int getFortunate(vector<int> a, vector<int> b, vector<int> c) · 85 test cases · 2 s / 256 MB per case

Submitting as anonymous