Peters Number
Imagine there is a person who likes numbers a lot and wants to choose a number that consists of n digits.But it has to be special. The person also wants it to have a sum of digits equal to s,which should be as large as possible .The number cannot have leading 0s.Can you help the person find that number or determine that it doesn’t exist.
Input:
The first line of input contains an integer n, representing the
number of digits in the requested number ,The second line of input contains
s,representing sum of digits
Output:
Print the requested number if it exists or -1 otherwise
Example1:
Input:
1
5
Output:
5
Example 2:
Input:
2
15
Output
96
Python code:
n=int(input())
sumed=int(input())
if len(str(sumed))==1:
for
i in range(9):
if
i==sumed:
print(i)
elif len(str(sumed))>1:
op=""
if
9*n<sumed:
print(-1)
else:
for
i in range(n):
if
9*i <sumed:
if sumed-(9*i)<9:
op='9'*i
op+=str(sumed-(9*i))
print(op)
0 Comments
Post a Comment