Skip to content
the poor coder

Hackerrank - Special Multiple Solution

Poor Man
Published
Updated
Reading time
1 min read

You are given an integer N. Can you find the least positive integer X made up of only 9's and 0's, such that, X is a multiple of N?

Update

X is made up of one or more occurences of 9 and zero or more occurences of 0.

Input Format
The first line contains an integer T which denotes the number of test cases. T lines follow.
Each line contains the integer N for which the solution has to be found.

Output Format
Print the answer X to STDOUT corresponding to each test case. The output should not contain any leading zeroes.

Constraints
1 <= T <= 104
1 <= N <= 500

Sample Input

Text
3
5
7
1

Sample Output

Text
90
9009
9

Explanation
90 is the smallest number made up of 9's and 0's divisible by 5. Similarly, you can derive for other cases.

Timelimits Timelimits for this challenge is given here

Solution in Python#

Python
from itertools import product
def special(n):
    i = 0
    while True:
        for j in product(*[[0,9]]*i) or [9]:
            s = "9"+"".join(map(str,j))
            if not int(s)%n:
                return s
        i+=1
            
for _ in range(int(input())):
    n = int(input())
    print(special(n))

Keep going

2020

Hackerrank - Bus Station Solution

There are groups of friends, and each group is numbered from 1 to . The th group contains people. They live near a bus stop, and only a single bus operates on this route. An empty bus arrives at the bus stop and all the…

2020

Hackerrank - K Candy Store Solution

Jim enters a candy shop which has N different types of candies, each candy is of the same price. Jim has enough money to buy K candies. In how many different ways can he purchase K candies if there are infinite candies…

2020

Hackerrank - Diwali Lights Solution

On the eve of Diwali, Hari is decorating his house with a serial light bulb set. The serial light bulb set has N bulbs placed sequentially on a string which is programmed to change patterns every second. If at least one…

ESC