A beauty factor

2

39 votes
Basic Programming, Bit Manipulation, Implementation, String Manipulation
Problem

You are given a positive integer n. The beauty factor of a number is the sum of digits obtained till the obtained sum is a single digit.

Example

  • Beauty factor of 1987 = 1+9+8+7 = 25 = 2+5 = 7
  • Beauty factor of 10 = 1+0 = 1

You are given a beauty factor, b. Your task is to find a minimum number (n) of length k whose beauty factor is b.

Here, the length of a number is defined as the number of digits a number has. 

Note: The digits of the number in the output must be distinct and must be a positive integer

Input format

The first line contains the beauty factor b (0<b<10) and the length of a number k (0<k<10).

Output format

Print the minimum number of length k whose beauty factor is b. If no such number is possible to make the beauty factor b with length k, then print 1.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

This is pretty starightforward. 149 is the least number which has beauty factor of 5 and the length of number is 3.

Note : Beauty factor of 149 = 1+4+9 = 14 = 1+4 = 5

Editor Image

?