LoopsyDoopsy
SRM 763 · 2019-07-16 · by abdullahkool768
Problem Statement
The number of loops in a digit is the number of closed regions you produce when you write the digit on paper. For example, "1" has no loops, "9" has one loop, and "8" has two. (As the number of loops depends on the font you use, the exact numbers of loops we are using in this problem are given in the Notes.)
By extension, the number of loops in any nonnegative integer is the total number of loops in its individual digits. For example, "2461" has two loops and "1890" has four.
You are given the
Notes
- The digits 0 through 9 have 1, 0, 0, 0, 1, 0, 1, 0, 2, and 1 loops, respectively.
Constraints
- loops will be between 1 and 2,500, inclusive.
1 Returns: "0"
0, 4, 6, 9, 10, 24 are some of the non-negative integers with exactly 1 loop.
2 Returns: "8"
8, 49, 66, 100 are some of the non-negative integers with exactly 2 loops.
3 Returns: "48"
2 Returns: "8"
15 Returns: "48888888"
40 Returns: "88888888888888888888"
Watch out for integer overflow.
Submissions are judged against all 157 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LoopsyDoopsy with a public method string getSmallestNumber(int loops) · 157 test cases · 2 s / 256 MB per case