A smallest number

2.8

70 votes
Algorithms, Basics of Greedy Algorithms, C++, Greedy Algorithms
Problem

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

1T101K5×105

Time Limit: 5
Memory Limit: 256
Source Limit:
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.
Editor Image

?