Question
We define 123-numbers according to the following rules. 1 is the smallest 123-number. n is a 123-number if and only if the only digits appearing
We define 123-numbers according to the following rules.
- 1 is the smallest 123-number.
- n is a 123-number if and only if the only digits appearing in the base-ten representation of n are the digits 1, 2, and 3, and if a digit appears, then the number of times it appears is also a 123-number.
For instance, 3 is a 123-number because it only involves the digit 3, this digit appears exactly 1 time, and we are given that 1 is a 123-number.
Knowing that 3 is a 123-number, we can now conclude that 1112 is a 123-number. 1112 contains only the digits 1 and 2. The digit 1 appears 3 times, and we know 3 is a 123-number. The digit 2 appears 1 time, and we know 1 is a 123-number.
In contrast, 2222 is not a 123-number. Although 2222 only uses the digit 2, this digit appears 4 times, and 4 is not a 123-number.
In ascending order, the first 123-numbers are: 1, 2, 3, 11, 12, 13, 21, 22, 23, 31, 32, 33, 111, 112, 113, 121, 122, 123, 131...
Write code in python to find what the 333rd and 5000th 123-number is.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started