Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Last Updated: 22 Feb, 2021

Moderate

```
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.
```

```
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.
```

```
You don’t have to print anything; it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 5
1 <= N <= 100000
Where ‘T’ is the total number of test cases, and N is the number.
```

- The repunits are 1, 11, 111, 1111, …. and the next repunit to X will always be X * 10 + 1.
- If the remainder left by repunit X is R, then the remainder left by the next repunit will always be (R * 10 + 1)% N. Since the repunit can be very large, there is no need to find the repunit number.
- Simply counting the number of ones will give us the answer.
- So, find out the remainders of all repunit numbers until the remainder becomes 0. Once it does, then the count of iterations done to make the remainder 0 will be the number of 1’s.

Similar problems

Ninja And The LCM

Easy

Posted: 12 Apr, 2022

A Number Game

Moderate

Posted: 23 Apr, 2022

Pair Product Div by K

Moderate

Posted: 15 May, 2022

Pair Product Div by K

Moderate

Posted: 15 May, 2022

Merge Two Sorted Arrays Without Extra Space

Moderate

Posted: 19 Nov, 2022

Co-Prime

Hard

Posted: 14 Dec, 2022