Problem:
 Score : 300 points    Problem Statement Takahashi loves the number 7 and multiples of K .  Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots ? (Also see Output and Sample Input/Output below.)  If the sequence contains no multiples of K , print -1 instead.      Constraints  1 \leq K \leq 10^6  K is an integer.         Input Input is given from Standard Input in the following format:  K       Output Print an integer representing the position of the first occurrence of a multiple of K . (For example, if the first occurrence is the fourth element of the sequence, print 4 .)        Sample Input 1 101      Sample Output 1 4  None of 7 , 77 , and 777 is a multiple of 101 , but 7777 is.       Sample Input 2 2      Sample Output 2 -1  All elements in the sequence are odd numbers; there are no multiples of 2 .       Sample Input 3 999983      Sample Output 3 999982

Solution (Python):
K = int(input())
a = 7
 
for n in range(1,1+K):
  if a%K==0:
    print(n)
    exit()
  a = (a*10+7)%K
 
print(-1)

Solution (Python):
K = int(input())
like = 7
ans = -1
for i in range(K):
    if like % K == 0:
        ans = i+1
        break
    like = (like*10+7) % K
print(ans)

Solution (Python):
k = int(input())
x = 7
ans = 1
flag = [False]*k
while x%k != 0:
    ans += 1
    x = (x*10%k+7)%k
    if flag[x]:
        ans = -1
        break
    flag[x] = True
print(ans)

Solution (Python):


import os,sys
from io import BytesIO, IOBase
def main():
    k = int(input())
    ans=val=7%k
    fin,n = -1,1
    se = set()
    while ans not in se:
        if not ans:
            fin = n
            break
        se.add(ans)
        val *= 10
        val %= k
        ans += val
        ans %= k
        n += 1
    print(fin)


BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

Solution (Python):
k = int(input())
a=7
i=1
if k%5==0 or k%2==0:
  print(-1)
  exit()
while True:
  if a%k ==0:
    print(i)
    break
  i+=1
  a=(a*10+7)%k

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
if K % 7 == 0:
    K //= 7

s = 1
for i in range(1,K+1):
    if s % K == 0:
        print(i)
        exit()
    else:
        s *= 10
        s += 1
        s %= K

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

k = inp()
if k%2 == 0 or k%5 == 0:
    print(-1)
    quit()
now = 0
for i in range(k+10000):
    now += pow(10,i+1,k)*7
    
    now %= k
    if now == 0:
        print(i+1)
        quit()

Solution (Python):
k = int(input())

a = 0
for i in range(k):
    a = 10*a + 7
    a = a % k
    if a == 0:
        print(i+1)
        exit()
print(-1)

Solution (Python):
k=int(input())
sevens=0
for i in range(1,k+1):
  sevens=(sevens*10+7)%k
  if sevens==0:
    print(i)
    exit()
print(-1)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



K = INT()

tmp = 7
ans = 1
p = 1
mo = tmp%K
checked = [0]*(K+1)
checked[mo] = 1
while mo != 0:
	mo += 7*pow(10, p, K)
	mo %= K
	p += 1
	if checked[mo]:
		print(-1)
		break
	checked[mo] = 1
else:
	print(p)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()

tmp = 7
ans = 1
p = 1
mo = tmp % K
checked = [0] *  (10 ** 6 + 1)
checked[mo] = 1

while mo != 0:
    mo = mo + 7 * pow(10, p, K)
    mo %= K
    p += 1
    if checked[mo]:
        
        print(-1)
        break
    checked[mo] = 1
else:
    print(p)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    """
    77...7 % K == 0  =>  7 * (10^n - 1) / 9 = K * x (for some x)
                     =>  10^n - 1 = 9 * (K * x) / 7
                     =>  10^n - 1 = L * y (L = 9 * K if K % 7 != 0 else 9 * K / 7)
                     =>  10^n ¥cong 1 (mod L)
    最後の言い換えが出てこなかったです。。。。。。
    Lが2, 5の倍数だと明らかに不適で、そうでない場合はオイラーの定理から
    これを満たすnが¥varphi(L)として書けるので、あとはそこまでを愚直に探索すれば良いと。。。
    """
    K = int(input())
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return

    if K % 7 == 0:
        K = K * 9 // 7
    else:
        K *= 9

    n = 1
    power = 10
    while True:
        if power % K == 1:
            print(n)
            return
        else:
            n += 1
            power *= 10
            power %= K

if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
import math
import time
import numpy as np

k = int(input())

if k %2 ==0 or k%5==0:
    print(-1)
else:
    if k %7 == 0:
        l = k*9//7
    else:
        l = k*9
    q = 10%l
    for i in range(1,1000000):
        if q ==1:
            print(i)
            break
        else:
            q = (q*10)%l
            pass

Solution (Python):
K = int(input())
a = 7

for n in range(1,1+K):
  if a%K==0:
    print(n)
    exit()
  a = (a*10+7)%K

print(-1)

Solution (Python):
import sys

k = int(input())

if k % 2 == 0 or k % 10 == 5:
    print(-1)
    sys.exit()
else:
    cnt = 1
    a = 0
    while(True):
        a = (a * 10 + 7) % k
        if a % k == 0:
            print(cnt)
            break

        if cnt > 1000000:
            print(-1)
            break

        cnt += 1

Solution (Python):
def main():
    K = int(input())
    if K%10:
        if K%7==0:
            K//=7
        L = 9*K
        mod = 10%L
        for i in range(9000001):
            if mod == 1:
                print(i+1)
                exit()
            mod = 10*mod%L
        print(-1)
    else:
        print(-1)
    

if __name__ == "__main__":
    main()

Solution (Python):
K = int(input())

if K % 2 == 0 or K % 5 == 0:
  print(-1)
  exit()
  
t = 7
if t % K == 0:
  print(1)
  exit()

t %= K

for i in range(2,K+1):
  t = t*10 + 7
  if t % K == 0:
    print(i)
    exit()
  else:
    t %= K
    
print(-1)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
if K % 7 == 0:
    K //= 7

A = [1]  
for i in range(K):
    A.append((A[-1]*10) % K)

s = 1
for i in range(1,K+1):
    if s % K == 0:
        print(i)
        exit()
    else:
        s += A[i]
        s %= K

Solution (Python):



import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    K = i2n()
    a = 0
    if K % 7:
        L = 9 * K
    else:
        L = 9 * K // 7
    a = 1
    for i in range(1, K + 10):
        a = (a * 10) % L
        if a == 1:
            print(i)
            return
    print('-1')
    return
 
main()

Solution (Python):
def main():
    k = int(input().strip())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    x = 7 % k
    for n in range(1, k + 1):
        if x == 0:
            print(n)
            return
        x = (10 * x + 7) % k

    print(-1)
    return


if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

k = readint()
a = 0
flag = -2
for i in range(10**6):
    a = (a + 7*pow(10,i,k)) % k
    if a==0:
        flag = i
        break
print(flag+1)

Solution (Python):
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    i = -1
else:
    if K % 7 == 0:
        K = K//7
    L = 9*K
    a = 10 % L
    if a == 1:
        i = 1
    else:
        for i in range(2, L+1):
            a = (a*10) % L
            if a == 1:
                break
print(i)

Solution (Python):
k=int(input())
if k%2==0 or k%5==0:
    print(-1)
    exit()

pw=1
tmp=7
ans=1

for _ in range(k):
    if tmp%k==0: 
        break
    ans+=1
    pw*=10
    pw%=k
    tmp+=7*pw
print(ans)

Solution (Python):
k = int(input())

if k%2 == 0 or k%5 == 0:
    print(-1)
else:
    n = 0
    cnt = 0
    while 1:
        n *= 10
        n += 7
        cnt += 1
        n %= k
        if n == 0:
            break
    print(cnt)

Solution (Python):
K = int(input())
 
x = 7 % K
for i in range(1, K+1):
    if x == 0:
        break
    x = (x * 10 + 7) % K
else:
    i = -1
 
print(i)

Solution (Python):
K=int(input())
now=7
ans=-1
for i in range(K):
    now = now % K
    if now ==0:
        ans=i+1
        break
    now=now *10 +7
print(ans)

Solution (Python):
k = int(input())

if k % 2 == 0 or k % 5 == 0:
  print(-1)
  exit()

a = 7
ans = 0
for i in range(10**7):
  a = a % k
  if a % k == 0:
    ans = i + 1
    break
  else:
    a = a*10 + 7
    ans = i + 1


print(ans)

Solution (Python):

def solve(K):
    a = 7 % K
    for i in range(1, K+1):
        if a == 0:
            return i
        a = (a * 10 + 7) % K
    return -1 

        

def solve0(K):
    a = 7
    for i in range(0, 10000):
        if a % K == 0:
            return i
        a = a*10+7
    return -1

K = int(input())
print(solve(K))

Solution (Python):
def main():
    k = int(input().strip())
    x = 7 % k
    ans = -1
    for n in range(1, k + 1):
        if x == 0:
            ans = n
            break
        x = (10 * x + 7) % k

    print(ans)
    return


if __name__ == "__main__":
    main()

Solution (Python):
K = int(input())
ans = -1
now = 7
for i in range(1, 10**6):
    if now % K == 0:
        ans = i
        break
    now *= 10
    now += 7
    now %= K

print(ans)

Solution (Python):
def solve(K):
	done = set()
	a = 7%K
	n = 1
	while a not in done:
		if a==0:
			return n
		else:
			done.add(a)
			a = (10*a+7)%K
			n += 1
	return -1

print(solve(int(input())))

Solution (Python):
n = int(input())
a = 0
cnt = 1
for i in range(1000001):
    a *= 10
    a += 7
    if a % n == 0:
        print(cnt)
        exit()
    a %= n
    cnt += 1
print(-1)

Solution (Python):
K = int(input())

if K % 7 == 0:
    K //= 7

tmp = 0
for i in range(0, K+1):
    tmp += pow(10, i, K)
    if tmp % K == 0:
        print(i+1)
        exit()
print(-1)

Solution (Python):
k = int(input())
r = 0
for i in range(1, k+1):
    r = (r*10 + 7)%k
    if r == 0:
        print(i)
        exit()
print(-1)

Solution (Python):
import sys
k = int(input())

num = 0
for i in range(k + 1):
    num = (num*10+7)%k
    if num == 0:
        print(i + 1)
        sys.exit()
print(-1)

Solution (Python):
K = int(input())
ans = -1
t = 0
for i in range(10**6):
  t = t * 10 + 7
  t %= K
  if t == 0:
    ans = i + 1
    break
print(ans)

Solution (Python):

K = int(input())
amari = set([])
cnt = 0
while True:
    cnt +=1
    if cnt ==1:
        num = 7
    else:
        num = (num*10+7)%K
    tmp = num%K

    if tmp == 0:
        print(cnt)
        exit()
    else:
        if tmp in amari:
            print(-1)
            exit()
        else:
            amari |=set([tmp])

Solution (Python):
import sys
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print('-1')
  sys.exit()
s = 7
c = 1
while True:
  if s % k == 0:
    break
  s = (10 * s + 7) % k
  c += 1
print(c)

Solution (Python):
K = int(input())

m = 7
count = 1



while  True:
    m = m % K
    if m == 0:
        print(count)
        break
    
    if count > K:
        print("-1")
        break

    m *= 10
    m += 7
    count += 1

Solution (Python):
import math as mt
n=int(input())
x=7%n
ten=1
for i in range(n):
  if x%n==0:
    print(i+1)
    break
  ten=((ten%n)*(10%n))%n
  x+=((ten%n)*(7%n))%n
else:
  if n==1:
    print(1)
  else:
    print(-1)

Solution (Python):


K = int(input())
ans = 1

if K % 2 == 0:
	print(-1)
	exit()
if K % 5 == 0:
	print(-1)
	exit()

temp = 7
for i in range(1*10**6):
	if temp % K == 0:
		print(ans)
		exit()
	res = temp % K
	temp = res*10 + 7
	ans += 1
print(-1)

Solution (Python):
K = int(input())
tmp = 7
for i in range(1,K+2):
    if tmp % K == 0:
        print(i)
        exit()
    tmp %= K
    tmp *= 10
    tmp += 7
print(-1)

Solution (Python):
k = int(input())

found = False
l = set()

n = 7
i = 0
while True:
    i += 1
    n %= k
    if n == 0:
        found = True
        break
    if n in l:
        break

    l.add(n)
    n = n * 10 + 7

if found:
    print(i)
else:
    print(-1)

Solution (Python):

 
import sys
 
def main():
    k = int(input())
    sevens=0
    if k%2==0:
      print(-1)
      exit()
    for i in range(1,10**6+1):
        sevens=(sevens*10+7)%k
        if sevens==0:
            print(i)
            exit()
    print(-1)
 
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
rm = 7%N
ans=-1
for i in range(N):
    if rm == 0:
        ans = i + 1
        break
    rm = (rm*10 + 7) % N

print(ans)

Solution (Python):
k = int(input())
a = 0
for i in range(k):
    a = (a*10+7)%k
    if a == 0:
        print(i+1)
        exit()
print(-1)

Solution (Python):
k=int(input())
if k%7==0:
    k//=7
res=1
if k%2==0 or k%5==0:
    print(-1)
else:
    k*=9
    for i in range(k):
        res*=10
        if res%k==1:
            print(i+1)
            break
        else:
            res%=k

Solution (Python):

 
import sys
 
def main():
    k = int(input())
    sevens=0
    if k%2==0:
      print(-1)
      exit()
    for i in range(1,k+1):
        sevens=(sevens*10+7)%k
        if sevens==0:
            print(i)
            exit()
    print(-1)
 
if __name__ == "__main__":
    main()

Solution (Python):

import os
import sys
from io import BytesIO, IOBase


def main():
    k = int(input())
    i = 1
    x = 7 % k
    seen = {x}
    while x != 0:
        x = (x * 10 + 7) % k
        i += 1
        if x in seen:
            print(-1)
            break
        seen.add(x)
    else:
        print(i)
    




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):

K=int(input())

if(K%2==0 or K%5==0):
  print("-1")

else:
  ans = 1
  s = 7
  while True:
    if s%K==0:
      print(ans)
      break
    else:
      s=(s%K)*10+7
      ans += 1

Solution (Python):
K = int(input())
a = 0
for i in range(K):
    a = (a + 7 * pow(10,i,K))%K
    if a == 0:
        print(i+1)
        exit()
print(-1)

Solution (Python):
k = int(input())
a = 0
for i in range(k):
    a = (a*10+7)%k
    if a == 0:
        print(i+1)
        exit()
print(-1)

Solution (Python):

MOD = 10 ** 9 + 7
INFI = 10**10

import math
from collections import deque
import itertools
import heapq

from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint




def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default




def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    
    k=int(input())
    a=7
    i=-1
    amari=0
    for j in range(1,k+2):
        temp=a%k
        if temp==0:
            i=j
            break
        a=(7+a*10)%k
    print(i)



if __name__ == "__main__":

    main()

Solution (Python):
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print(-1)
else:
  myconst = 7 % k
  cnt = 1
  while True:
    if not myconst:
      print(cnt)
      break
    else:
      myconst = ((10 * myconst) + 7) % k
    cnt += 1

Solution (Python):
k = int(input())
ok = [0]*k
x=7 % k
ok[x] = 1
if x == 0:
  print(1)
else:
  now = 1
  while 1:
    now += 1
    x = (x*10 +7) % k
    if ok[x] == 1:
      print(-1)
      break
    elif x == 0:
      print(now)
      break
    else:
      ok[x] = 1

Solution (Python):
k = int(input())

m = 0
for i in range(k):
    m = (m*10 + 7)%k
    if m == 0:
        ans = i + 1
        break

if m == 0:
    print(ans)
else:
    print(-1)

Solution (Python):
k=int(input())
if k%2==0 or k%5==0:
    print(-1)
else:
    num=0
    for i in range(k):
        num=(num*10+7)%k
        if num==0:
            print(i+1)
            break

Solution (Python):
k = int(input())
if k % 2 == 0 or k%5==0:
    print(-1)
    exit()
a = 7
ans = 1
while True:
    if a % k == 0:
        print(ans)
        exit()
    a = (a*10+7) % k
    ans += 1

Solution (Python):
from itertools import count

k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    m = 0
    for i in count(0):
        m += pow(10, i, k) * 7
        m %= k
        if m == 0:
            print(i+1)
            break

Solution (Python):
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

ans, num = 1, 7
while 1:
    if num % k == 0:
        print(ans)
        break
    ans += 1
    num = (num % k) * 10 + 7

Solution (Python):
import sys
k = int(input())
d = 0
for i in range(k+1):
  d = (10*d) + 7
  d %= k
  if d == 0:
    print(i+1)
    sys.exit()
print(-1)

Solution (Python):
K = int(input())
md = 0
if K % 2 == 0:
    print(-1)
    exit()
for i in range(10 ** 6):
    a, b = divmod(md + 7 * (pow(10, i, K)), K)
    if b == 0:
        print(i + 1)
        exit()
    else:
        md = b
print(-1)

Solution (Python):
import sys
k = int(sys.stdin.readline().rstrip("\n"))
n = 0
for i in range(k+1):
    n = 10*n+7
    n = n%k
    if n == 0:
        print(i+1)
        break
else:
    print(-1)

Solution (Python):

 
import sys
 
def main():
    k = int(input())
    sevens=0
    for i in range(1,10**6+1):
        sevens=(sevens*10+7)%k
        if sevens==0:
            print(i)
            exit()
    print(-1)
 
if __name__ == "__main__":
    main()

Solution (Python):
k=int(input())
n=7
ans=1
if k%2==0 or k%5==0:
    print(-1)
    exit()
while n%k!=0:
    n=(n*10+7)%k
    ans+=1
print(ans)

Solution (Python):
K = int(input())
sevens = 0
for i in range(1, 10 ** 6):
  sevens = sevens * 10 + 7
  if sevens % K == 0:
    print(i)
    break
  if (sevens > K):
    sevens %= K
else:
  print(-1)

Solution (Python):
K = int(input())
c = 0
s = 0
LIM = 1000000
if K % 2 == 0 or K % 5 == 0:
  print("-1")
else:
  while (c <= LIM):
    c = c + 1
    s = (s*10 + 7) % K
    if (s == 0):
      break
  if ( c > LIM):
    print("-1")
  else:
    print(c)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math
import bisect

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()


x = 0
k = readInt()
a = 7%k
ans = 0
for i in range(10**6+1):
	x = (x*10%k+a)%k
	ans += 1
	if x==0:
		print(ans)
		exit()

print(-1)

Solution (Python):
K = int(input())

if K == 7:
    print(1)
elif K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    count = 0
    num = 0
    while True:
        num = (num * 10 + 7) % K
        count += 1
        if num == 0:
            print(count)
            break

Solution (Python):
K = int(input())
n = 0
for i in range(1, 1010101):
    n = (n*10 + 7) % K
    if n == 0:
        print(i)
        exit()
else:
    print(-1)

Solution (Python):
K = int(input())
seven = 7
counter = 1
flag = True
for i in range(K):
    if seven % K == 0:
        print(counter)
        flag = False
        break
    seven = (seven * 10 + 7) % K
    counter += 1
if flag:
    print(-1)

Solution (Python):
K = int(input())
rest = 7%K
count=1
while (count<=K):
    if rest == 0:
        print(count)
        exit()
    count +=1
    rest = (rest%K*10 + 7)%K
print(-1)

Solution (Python):
K = int(input())
a = 0
t = 1
for i in range(K):
    a += 7*t
    a = a % K
    t = t*10
    t = t%K
    if a == 0:
        print(i+1)
        exit()
print(-1)

Solution (Python):
K = int(input())
a = 0
for i in range(K):
    a = (10*a+7)%K
    if a == 0:
        print(i+1)
        exit()
print(-1)

Solution (Python):
import sys

k = int(input())
n = 7
for i in range(k):
  if (n % k == 0):
    print(i + 1)
    sys.exit()
  n = (n * 10 + 7) % k

print(-1)

Solution (Python):
K = int(input())

i = 0
iCnt = 0
while iCnt <= 10**6:
  iCnt += 1
  i = (i * 10 + 7) % K
  if i % K == 0:
    print(iCnt)
    exit()

print(-1)

Solution (Python):
k = int(input())
a = 7

for i in range(1, 1000000):
  if a % k == 0:
    print(i)
    exit()
  a = (a * 10 + 7) % k
print(-1)

Solution (Python):
K = int(input())
s = 7
digit = 1
for i in range(K): 
    if s % K == 0:
        break
    digit += 1
    s = int(str(s) + '7') % K 
if s % K == 0:
    print(digit)
else:
    print(-1)

Solution (Python):
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

num = 7
for i in range(1,10**6):
    if num % k == 0:
        print(i)
        break
    num = (num % k) * 10 + 7

Solution (Python):
def main():
    K = int(input())
    if K%2 == 0 or K%5==0:
        return -1

    if K % 7 == 0:
        L = K * 9 // 7
    else:
        L = K * 9
    
    for i in range(1, 10000000):
        x = pow(10, i, L)
        if x == 1:
            return i
    else:
        return -1


if __name__ == "__main__":
    ans = main()
    print(ans)

Solution (Python):
k = int(input())
val = 7
if k%2 == 0:
    ans = -1
elif k%5 == 0:
    ans = -1
else:
    for i in range(1,10**12+1):
        if val >= k:
            sub = val % k
            if sub == 0:
                  ans = i
                  break
            else:
                  val = 10 * sub + 7
        else:
            val = 10 * val + 7
print(ans)

Solution (Python):
K=int(input())

i=1
d=7

m=d % K
ML = [0 for i in range(1000000)]
while m != 0:
    ML[m]=1
    i+=1
    d=m*10+7
    m = d % K
    if ML[m] != 0:
        break

if m != 0:
    ans = -1
else:
    ans = i

print(ans)

Solution (Python):




def input_int():
    return int(input())



def int1(x):
    return int(x) - 1



def input_to_int_map():
    return map(int, input().split())



def input_to_int_tuple():
    return tuple(map(int, input().split()))



def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    k = input_int()
    t = 7
    for i in range(1000000):
        t %= k
        if t == 0:
            print(i + 1)
            return
        t = t * 10 + 7

    print(-1)


if __name__ == "__main__":
    main()

Solution (Python):
K = int(input())
i = 1
N = 0
if K%2==0:
    print(-1)
    exit()
while(i<1000000):
    N = N*10+7
    N %= K
    if N == 0:
        print(i)
        exit()
    i += 1
print(-1)

Solution (Python):
def solution(K: int) -> int:
    sevens: int = 0
    for i in range(1, K + 1):
        sevens = (sevens*10 + 7) % K
        if sevens == 0:
            return i
    return -1


K: int = int(input())

print(solution(K))

Solution (Python):
k = int(input())

mods = [7 % k]
for _ in range(10 ** 6):
    if mods[-1] == 0:
        print(len(mods))
        exit()
    mods.append((mods[-1] * 10 + 7) % k)
print(-1)

Solution (Python):
K = int(input())

repsept = 7
for i in range(1, K+1):
    if repsept % K == 0:
        print(i)
        break
    repsept = (repsept*10 + 7) % K
else:
    print(-1)

Solution (Python):
from collections import deque
import sys
input = sys.stdin.readline
 
k = int(input())
n = 7
ans = -1
 
for i in range(10**6): 
  if n % k  == 0:
    ans = i+1
    break
  else:
    n =  (n % k) *10 + 7
    
print(ans)

Solution (Python):
k=int(input())


if k%2==0 or k%5==0:
    print(-1)
    exit(0)

d={}

x=7
i=1
while True:
    if x%k==0:
        print(i)
        exit(0)

    x=(10*x + 7)%k
    if x not in d:
        d[x]=1
    else:
        print(-1)
        exit(0)


    i+=1

Solution (Python):
K = int(input())

if K == 1 or K == 7:
    print(1)
    exit()

v = 7
M = set([])
for i in range(1, K + 1):
    v = (v * 10 + 7) % K
    if v == 0:
        print(i + 1)
        exit()
    if v not in M:
        M.add(v)
    else:
        print(-1)
        exit()

Solution (Python):
k = int(input())
if k % 2 < 1 or k % 5 < 1:
    print(-1)
else:
    c = 1
    mod = 7 % k
    while mod > 0:
        mod += pow(10, c, k)*7
        mod %= k
        c += 1
    print(c)

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    k = int(input())
    r = 0
    for i in range(k + 10):
        r = (10 * r + 7) % k
        if r == 0:
            print(i + 1)
            return
    print(-1)
resolve()

Solution (Python):
k=int(input())
ama=[0]*(k)
now=7
if now%k==0:
  print(1)
  exit()
else:
  ama[now%k]+=1
for _ in range(2*k):
  now=(now*10+7)%k
  if now%k==0:
    print(_+2)
    exit()
  elif ama[now%k]==0:
    ama[now%k]+=1
  else:
    print(-1)
    exit()

Solution (Python):

import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

k = inp()
dt = {}
no = 0
ans = -1
i = 0
while True:
    no = (no*10+7)%k
    if no in dt:
        break
    dt[no] = 1
    
    if no == 0:
        ans = i+1
        break
    i += 1
print(ans)

Solution (Python):
K = int(input())
a = 7
ans = 1
for i in range(K):
    a= a % K
    if a == 0:
        print(ans)
        break
    else:
        a = a * 10 + 7
        ans += 1
else:
    print(-1)

Solution (Python):
K=int(input())
num=7
for i in range(1000000):
  modnum=num%K
  if modnum==0:
    print(i+1)
    exit()
  num=modnum*10+7
print(-1)