Cosmic Number

Given a single integer N, your task is to find the smallest number such that the sum of its digits is N and it is divisible by 10N.

Examples:

Input : N = 5
Output : 500000
500000 is the smallest number divisible
by 10^5 and sum of digits as 5.

Input : N = 20
Output : 29900000000000000000000

Input:
First line of the input contains an single integer T, denoting the number of test cases. Then T test cases follows. The only line of each test case contains a single integer N.

Output:
For each test case output the required answer on a new line.

Constraints:
1 <= T <= 50
0 <= N <= 100

Example:
Input:

2
6
19
Output:
6000000
1990000000000000000000



=======================================================


t=int(input())

for i in range(t):

    n=int(input())

    if n==0:

        print(0)

    else:

        if n%9!=0:

            print(n%9,end='')

        print('9'*(n//9)+'0'*n)

    



Comments

  1. t=int(input())
    for i in range(t):
    a=int(input())
    tmp=a
    for i in range(1,10**a):
    if i%a==0:
    s=0
    while(i!=0):
    rem=i%10
    s+=rem
    i=i//10
    if(s==tmp):
    break
    print(i*10**a)

    ReplyDelete
  2. testCases = int(input().strip())
    while testCases > 0:
    testCases -= 1
    n = int(input().strip())
    if n == 0:
    print(0)
    else:
    if n % 9 != 0:
    print(n % 9, end ='')
    print('9' * (n // 9) + '0' * n)

    ReplyDelete

Post a Comment

Popular posts from this blog

Count the Reversals

Change Bits