A smallest number
Practice
2.8 (70 votes)
Algorithms
Basics of greedy algorithms
C++
Greedy algorithms
Problem
35% Success 5611 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code
You are given an integer $$K$$.
Find the smallest number $$N$$ such that $$N$$ has exactly $$K$$ digits and none of the digits in $$N$$ is $$0$$. Also, the product of digits in number $$N$$ is greater than or equal to the sum of digits in number $$N$$.
Input format
- The first line contains an integer $$T$$ denoting the number of test cases.
- For each test case, the first line contains an integer $$K$$.
Output format
For each test case in a new line, print the smallest number $$N$$ that satisfies the given condition.
Constraints
\(1 \le T \le 10\)
\(1 \le K \le 5 \times 10^5\)
Explanation
- For first test case, N = 1 is the smallest number which has product of digits i.e. 1 greater than or equal to sum of digits i.e. 1.
- For second test case, N = 123 is the smallest number which has product of digits i.e. 6 greater than or equal to sum of digits i.e. 6.
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
23 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:30
17 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Points:30
6 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output