Soluție HackerRank pentru Special Multiple, subdomeniul Fundamentals, în Python 3. Include cerința formatată, exemple, explicația pașilor și cod sursă.

  • Problemă: Special Multiple
  • Domeniu: Fundamentals
  • Limbaj: Python 3

Challenge: Special Multiple

Subdomeniu: Fundamentals (fundamentals)

Scor cont: 30.0 / 30

Submission status: Accepted

Submission score: 1.0

Submission ID: 464727434

Limbaj: python3

Link challenge: https://www.hackerrank.com/challenges/special-multiple/problem

Cerință

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 <= 10<sup>4</sup>
1 <= N <= 500

Sample Input

3
5
7
1

Sample Output

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](https://www.hackerrank.com/environment)

Cod sursă

#!/bin/python3

import math
import os
import random
import re
import sys

def solve(n):
    i = 0
    while True:
        i += 1
        x = int(bin(i)[2:]) * 9
        if x % n == 0:
            return str(x)
if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    t = int(input().strip())

    for t_itr in range(t):
        n = int(input().strip())

        result = solve(n)

        fptr.write(result + '\n')

    fptr.close()
HackerRank Fundamentals – Special Multiple