Given a positive integer K, you need find the smallest positive integer N such that N is divisible by K, and N only contains the digit 1. Return the length of N. If there is no such N, return -1. Example 1: Input: 1 Output: 1 Explanation: The smalle…
class Solution(object): def smallestRepunitDivByK(self, K: int) -> int: if K % 2 == 0 or K % 5 == 0: return -1 r = 0 for N in range(1, K + 1): r = (r * 10 + 1) % K if r == 0: return N…