Given a positive integer ‘N’ whose unit digit is 3. Find the number of 1's in the smallest repunit, which is divisible by the given number N. Every number whose unit digit is 3 has a repunit as its multiple. A repunit is a number that has only 1. It is of the form (10 * N – 1)/9.
Input format :
The first line of input contains an integer T denoting the number of test cases.
The next line contains an integer 'N', whose unit’s digit is 3.
Output format :
For each test case, a number of 1s in the smallest repunit is divisible by the given number N.
The output of each test case will be printed in a separate line.
Note:
You don’t have to print anything; it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 5
1 <= N <= 100000
Where ‘T’ is the total number of test cases, and N is the number.
1
3
3
The number 111 is the first repunit which is divisible by 3.
1
13
6
Generalize the sequence.
O(N), where N denotes the given number.
We are looping remainder from 1 till it becomes perfectly divisible by N, therefore the final time complexity will be O(N).
O(1)
Since we are not using any extra space.