Given a number H which represent the total number of holes. The task is to find the smallest number which has that many numbers of holes.
- 0, 4, 6, 9 has 1 holes each and 8 has 2 holes in it.
- The number should not contain leading zeros.
Input: H = 1
Input: H = 5
Number which has 5 holes in it is 488. i.e (1 + 2 + 2)
- First of all, Check whether the number of holes given is 0 or 1, if 0 then print 1 and if 1 then print 0.
- If number of holes given is more than 1 then divide the number of holes by 2 and store the remainder in ‘rem’ variable. and quotient in ‘quo’ variable.
- Now, if value of rem variable is equal to 1 then first print 4 once and then print 8 quo number of times.
- Else print 8 only quo number of times.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Assign Mice to Holes
- Find smallest number with given number of digits and sum of digits under given constraints
- Program to find count of numbers having odd number of divisors in given range
- Program to find absolute value of a given number
- C program to find square root of a given number
- Program to calculate the number of odd days in given number of years
- Find the smallest number whose digits multiply to a given number n
- Find the Largest number with given number of digits and sum of digits
- Find maximum number that can be formed using digits of a given number
- Given a number N in decimal base, find number of its digits in any base (base b)
- Find the largest good number in the divisors of given number N
- Given number of matches played, find number of teams in tournament
- Find the total number of composite factor for a given number
- Find Next number having distinct digits from the given number N
- Find smallest possible Number from a given large Number with same count of digits
- Find Nth number in a sequence which is not a multiple of a given number
- Find smallest number formed by inverting digits of given number N
- Check if the given array can be reduced to zeros with the given operation performed given number of times
- Queries to increment array elements in a given range by a given value for a given number of times
- Check whether all the rotations of a given number is greater than or equal to the given number or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.