Numbers are Easy
InterviewTime limit1sMemory limit256 MB
Find the smallest positive multiple of N whose decimal digits are only 0 and 1 for each test case.
- Level
Medium5 of 10
- Topics
- BFS, Graph, Number theory
- Solved
- No attempts yet
Problem
You are given an integer . Find the smallest positive integer that is divisible by and whose base 10 representation uses only the digits 0 and 1.
Input
The first line contains the number of test cases ().
Each of the next lines contains one integer ().
Output
For each test case, print on its own line the smallest positive integer that is divisible by and contains only the digits 0 and 1.
Under these constraints a solution always exists, and it fits in a signed 64 bit integer.