Every number whose unit’s digit is 3 has a repunit as its multiple. A repunit is a number which has only ones. It is of the form (10^{n} – 1)/9. Example: 3 divides 111, 13 divides 111111.
A positive integer N will be given whose unit’s digit is 3. The task is to find the number of 1s in the smallest repunit which is divisible by the given number N.
Example 1:
Input: N = 3
Output: 3
Explaination: The number 111 is the first 
repunit which is divisible by 3.
Example 2:
Input: N = 13
Output: 6
Explaination: The first repunit is 111111 
which divisible by 13.
Your Task:
You do not need to read input or print anything. Your task is to complete the function repUnit() which takes N as input parameter and returns the number of 1 in the smallest repunit which is divisible by N.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def repUnit(self, N):
        # code here

Solutions:
class Solution:

	def repUnit(self, N):
		count = 1
		remain = 1 % N
		while remain:
			remain = remain * 10 + 1
			remain = remain % N
			count += 1
		return count


class Solution:

	def repUnit(self, n):
		n1 = 3
		n2 = 111
		while True:
			if n2 % n == 0:
				return n1
			n2 = (n2 * 10 + 1) % n
			n1 += 1


class Solution:

	def repUnit(self, N):
		c = 1
		r = 1
		while r != 0:
			r = (r * 10 + 1) % N
			c += 1
		return c


import math

class Solution:

	def repUnit(self, N):
		length = 1
		d = 1
		while True:
			d = (d * 10 + 1) % N
			length += 1
			if d == 0:
				break
		return length


class Solution:

	def repUnit(self, N):
		if N == 1:
			return 2
		d = 1
		count = 1
		while True:
			d = (d * 10 + 1) % N
			count += 1
			if d == 0:
				break
		return count


class Solution:

	def repUnit(self, N):
		x = 1
		y = 1
		while x != 0:
			x = x * 10
			x += 1
			x %= N
			y += 1
		return y