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())

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

  print(cnt)

Solution (Python):
K = int(input())
a = 7 % K
cnt = 1
while a:
    a = (10*a+7) % K
    cnt += 1
    if K < cnt:
        cnt = -1
        break
print(cnt)

Solution (Python):

"""
Created on Fri Aug  7 01:25:53 2020

@author: saito
"""








K = int(input())


r = 0
answer = -1
h = []

for cnt in range(K):
    r = (10*r+7) % K
    if r == 0:
        answer = cnt + 1
        break


print(answer)

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

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

print(-1)

Solution (Python):
'''
Created on 2020/08/22

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  K=int(pin())
  a=7%K
  for i in range(K):
    if a%K==0:
      print(i+1)
      break
    a=(10*a+7)%K
  else:
    print(-1)
  return 
main()

Solution (Python):
def main(h):
  count = 1
  n = 0
  for i in range (k):
    n = (n * 10 + 7) % k  
    if n == 0: 
      print(count)
      return 0
    count += 1
  print(-1)
  
if __name__ == '__main__':
  k = int(input())
  main(k)

Solution (Python):
import sys
K = int(input())
ans = 0
cur = 0
for i in range(10**6):
    cur += (7 * pow(10, i, K))%K
    if cur % K == 0:
        print(i+1)
        sys.exit()
    cur %= K
print(-1)

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

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

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

Solution (Python):
def function(x):
    base = 0
    for i in range(1, 10 ** 7):
        base *= 10
        base += 7
        base %= x
        if base == 0:
            return i

    return -1

x = int(input())
print(function(x))

Solution (Python):
K = int(input())
count = 1
n = 0
if K % 2 == 0 or K % 5 == 0:
    count = -1
    print(count)
else:
    while True:
        n = (n*10+7)%K
        if n == 0:
            break
        count += 1
    print(count)

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

Solution (Python):



K = int(input())
count = 0
a = 0
if K % 2 == 0 or K % 5 == 0:
  print(-1)
  exit()

while True:
  a = (a*10 + 7)%K
  count += 1
  if a == 0:
    break
print(count)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def main():
    k = II()
    sevens = 7%k
    for i in range(1, k+1):
        if sevens % k == 0:
            print(i)
            return
        sevens = (10*sevens + 7)%k
    print(-1)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    k = int(input())
    seven = 7
    already = set()
    cnt = 0
    if k%2==0:
        print(-1)
        return 
    while seven != 0:
        if seven in already:
            print(-1)
            return 
        seven %= k
        already.add(seven)
        cnt += 1 
        if seven != 0:
            seven = seven * 10 + 7
    print(cnt)
    return

if __name__ == '__main__':
    main()

Solution (Python):
x = int(input())
if x % 2 == 0 or x % 5 == 0:
  print(-1)
else:
  s = 1
  m = 7
  
  while m%x != 0:
    n = m % x
    m = n * 10 +7
    s += 1
    
  
  print(s)

Solution (Python):
def main():
    K = int(input())
 
    work = 7
 
    answer = -1
    for i in range(1, K+1):
        i_mod = work % K
        if i_mod == 0 :
            answer = i
            break
        work = i_mod * 10 + 7
    print(answer)
main()

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

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

L = 9 * K

ans = -1

r = 10

for i in range(L):
    r %= L
    if r == 1:
        ans = i + 1
        break
    else:
        r = 10 * r

print(ans)

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

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

L = 9 * K

ans = -1

r = 10

for i in range(L):
    if r % L == 1:
        ans = i + 1
        break
    else:
        r = 10 * (r % L)

print(ans)

Solution (Python):

from math import sqrt


def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if 0 == k % 7 else k)
    if 0 == l % 2 or 0 == l % 5:
        return '-1'

    r = phi = l
    for i in range(2, int(sqrt(l)+1)):
        if 0 == r % i:
            phi = phi*(i-1)//i
            while 0 == r % i:
                r //= i
    if 1 < r:
        phi = phi*(r-1)//r

    D = set()
    for d in range(1, int(sqrt(phi)+1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi//d)

    ret = -1
    for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
k=int(input())
if k%2==0:
  print(-1)
  exit()
  
ans=1
pin=7
mod=k

for i in range(1000000):
  if pin%k==0:
    print(ans)
    exit()
    
  ans+=1
  pin*=10
  pin+=7
  pin%=mod
  

print('-1')

Solution (Python):



def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if k % 7 == 0 else k)
    if l % 2 == 0 or l % 5 == 0:
        return '-1'

    r = phi = l
    for i in range(2, int(-pow(l, 1/2))):
        if r % i == 0:
            phi = phi//i*(i-1)
            while r % i:
                r //= i

    a = 10 % l
    ret = 1
    while(a != 1):
        a = a*10 % l
        ret += 1
        if phi < ret:
            ret = -1
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

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

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

    work = 7

    answer = -1
    for i in range(1, K+1):
        i_mod = work % K
        if i_mod == 0 :
            answer = i
            break
        work = i_mod * 10 + 7
    print(answer)
main()

Solution (Python):



def solve(*args: str) -> str:
    k = int(args[0])

    ret = 1
    a = 7 % k
    while(a):
        a = (a*10+7) % k
        ret += 1
        if k < ret:
            ret = -1
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
K = int(input())
a = 7 % K
mods = []

i = 0
found = False
while (i <= K):
    i += 1
    if a == 0:
        print(i)
        found = True
        break
    a = (10 * a + 7) % K

if not found:
    print(-1)

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

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

print(-1)

Solution (Python):

import sys
from itertools import chain





7777


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


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    
    K = int(next(tokens))  
    answer = solve(K)
    print(answer)


if __name__ == "__main__":
    main()

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

Solution (Python):
k = int(input())
x = 7%k
cnt = 0

if k%2 ==0:
    print('-1')
else:
    while True:
        cnt += 1
        if x == 0:
            print(cnt)
            break
        elif cnt == k:
            print('-1')
            break
        else:
            x = (x*10+7)%k

Solution (Python):
import sys
input = sys.stdin.readline




'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

k=int(input())
if k%2==0:
    print("-1")
    sys.exit()

flg=False
cnt=0
a=7
for i in range(k):
    cnt+=1
    a%=k
    if a%k==0:
        print(cnt)
        sys.exit()
    a*=10
    a+=7

if not flg:
    print(-1)

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

Solution (Python):
k=int(input())
s=7
i=1
while s%k!=0:
  i+=1
  s=10*(s%k)+7
  if i==k+1:
    break
else:
  print(i)
  exit()
print(-1)

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

x = 7%K

for i in range(0,K+1):
    if x== 0:
        print(count)
        break

    count+=1
    x = (x*10+7)%K

if i== K:  
    print(-1)

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

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

Solution (Python):

K=int(input())
i=0
if K%2==0 or K%5==0:
    print('-1')

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

Solution (Python):
import sys 
K = int(input())
if K%5==0 or K%2==0:
    print("-1")
    sys.exit()

A = 0
for i in range(K):
    A = (10 * A + 7) % K
    if A == 0:
        print(i+1)
        break

Solution (Python):



def main():
    k = int(input())
    num = 0
    soeji = 0
    ar = [0 for _ in range(k)]

    while True:
        
        if ar[soeji] > 0:
            break
        ar[soeji] = num
        soeji = (soeji * 10 + 7) % k
        num += 1

    print(-1 if ar[0] == 0 else ar[0])


if __name__ == '__main__':
    main()

Solution (Python):
import sys
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print('-1')
    sys.exit()

A = 0
for i in range(K):
    A = (10 * A + 7) % K
    if A == 0:
        print(i+1)
        break

Solution (Python):

K= int(input())

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

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

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

ai_1 = 0
for i in range(K):
    ai = (10*ai_1 + 7)%K
    if ai==0:
        print(i+1)
        exit()
    ai_1 = ai

print("-1")

Solution (Python):
import sys
import numpy as np  
import numba  
from numba import njit, b1, i4, i8, f8  

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


@njit((i8, ), cache=True)
def main(K):
    for i in range(K):
        if i == 0:
            a = 7 % K
        else:
            a = (a * 10 + 7) % K
        if a == 0:
            return i + 1

    return -1


K = int(readline())

print(main(K))

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

x = 7
for ans in range(1, K*2):

    if  x%K == 0:
        print(ans)
        sys.exit()

    x = (x*10 + 7) % K
print(-1)

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

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

Solution (Python):

K=int(input())
a_i=7%K
i=1
if a_i==0:
	exit(print(1))
while True:
	i+=1
	a_i=(10*a_i+7)%K
	if a_i==0:
		print(i)
		exit()
	if i>=K:
		print(-1)
		exit()

Solution (Python):
def main():
    k=int(input())
    s=7
    for i in range(10**6):
        if s%k == 0:
            print(i+1)
            break
        s = (s*10+7)%k
    else:
        print(-1)

if __name__ == "__main__":
    main()

Solution (Python):
str = input()
num = int(str)
if num % 2 == 0:
  print('-1');
else:
  i = 1
  j = 7
  while j % num != 0 and i <= num:
    j = (j % num) * 10 + 7
    i += 1
  if i > num:
    print('-1');
  else:
    print(i);

Solution (Python):
k=int(input())
cnt=1
mod=7

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

if mod%k==0:
    print(cnt)
else:
    print(-1)

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

K = int(input())

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

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

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

print(-1)

Solution (Python):
K = int(input())
seven_number = 0
ality = 0
for ans in range(1,10**7):
        if ans > K:
            print("-1")
            break
        else:
            seven_number = (seven_number*10+7) % K
            if seven_number ==0:
                print(ans)
                break

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

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]







k = I()
n = 0
c = 0

for i in range(10**6):
    c += 1
    n = ( 10*n + 7 )%k
    if n==0:
        print(c)
        exit()

print(-1)
exit()

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

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

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

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

    a =7%k
    if a == 0:
        print(1)
        sys.exit()

    for i in range(2,10**7):
        a = (10*a+7) % k
        if a == 0:
            print(i)
            sys.exit()

    print(-1)
    
main()

Solution (Python):
import sys

k = int(input())

a =7%k
if a == 0:
    print(1)
    sys.exit()

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

Solution (Python):





def lg(value):
    flag = False
    flag = True
    if flag:
        print(str(value))



def xt(log):
    lg('★exit() - ' + str(log))
    exit()



def get_results():

    
    lines = list()
    
    lines_count = 1
    
    
    
    
    
    for _ in range(lines_count):
        lines.append(input())

    
    
    K = int(lines[0])
    
    
    
    
    
    
    
    
    

    result = 0

    tmp = 7

    if K % 5 == 0 or K % 2 == 0:
        return [-1]

    for k in range(K):

        q, mod = divmod(tmp, K)
        if mod == 0:
            return [k+1]
        tmp = mod * 10 + 7



def main():
    results = get_results()

    for result in results:
        print(result)



if __name__ == '__main__':
    main()

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

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

Solution (Python):
x = int(input())
cnt = 1
mod = 7

for i in range(x):
    if mod % x == 0:
        print(cnt)
        exit()
    mod = (10 * mod + 7) % x
    cnt += 1
print(-1)

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

Solution (Python):
K = int(input())
count = 1
mod = 7
answer = -1

for _ in range(K):
    if mod % K == 0:
        answer = count
        break
    count += 1
    mod = (mod * 10 + 7) % K

print(answer)

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

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

num = 0
cnt = 0
ans = -1

for i in range(K):
    num = num*10 +7
    cnt += 1
    if num%K != 0:
        num = num%K
    else:
        ans = cnt
        break
    
print(ans)

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

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

Solution (Python):
K = int(input())
Ans = -1

if K % 2 == 0 or K % 5 == 0:

  pass
  
elif 7 % K == 0:
  Ans = 1
  
else:
  pre_modK = 7 % K
  for i in range(2,K+1):
    modK = pre_modK * 10 + 7
    if modK % K == 0:
      Ans = i
      break
    else:
      pre_modK = modK % K

print(Ans)

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

i = 0
now = 0

if (0 == (Kin % 2)) or (0 == (Kin % 5)):
    print(-1)
else:
    while 1:
        now = (now * 10 + 7) % Kin
        i+=1

        if now == 0:
            break
    print(i)

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k = ni()

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

Solution (Python):
import sys

k = int(input())

ans = [0]*(k+1)
ans[0] = 7 % k

if ans[0] == 0:
    print(1)
    
else:
    for i in range(k):
        ans[i+1] = (ans[i]*10 + 7) % k
        
        if ans[i+1] == 0:
            print(i+2)
            sys.exit()
            
    print(-1)

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

    rem = set()
    n = ans = 0

    while True:
        n = n * 10 + 7
        ans += 1

        if n % K == 0:
            print(ans)
            break
        else:
            n = n % K
            
            if n in rem:
                print(-1)
                break
            else:
                rem.add(n)
                
if __name__ == "__main__":
    main2()

Solution (Python):
K = int(input())
ans = '-1'
mod = 7%K
path = [mod]
for i in range(1,K+1):
  if mod == 0:
    ans = i
    break
  mod = (mod*10 + 7)%K
  path.append(mod)
  if mod == path[0]:
    ans = '-1'
    break
print(ans)

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

Solution (Python):
K = int(input())
INF = 10**18

a = [INF] * (K+1)
a[0] = 0

for n in range(1, K+1):
    a[n] = (10 * a[n-1] + 7) % K
    if a[n] == 0:
        print(n)
        break
else:
    print(-1)

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

mod = 7%k
path = [mod]
ans = '-1'

for i in range(1,k+1):
    if mod == 0:
        ans = i
        break
    mod = (mod*10 + 7)%k
    path.append(mod)
    if mod == path[0]:
        ans = '-1'
        break

print(ans)

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

i = 0
mod = 0
while True:
    mod = (mod*10 + 7)%k
    i += 1
    if mod == 0:
        print(i)
        break

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

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

print(-1)

Solution (Python):

k = int(input())
ans = 0
n = 7

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

print(c)

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

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

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

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

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

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

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

ai = 0
for i in range(k+2):
    ai = ((ai * 10) + 7) % k
    if ai == 0:
        ans = i + 1
        print(ans)
        exit()

ans = -1
print(ans)

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

Solution (Python):
K = int(input())
N = 10**6
a = [0] * N

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

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

A = [0]*1000001
A[0] = 7%K
ans = -1

for i in range(1,1000001):
    A[i] = (A[i-1]*10+7)%K

for i in range(1000001):
    if A[i]==0:
        ans = i+1
        break
        
print(ans)

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

Solution (Python):
K = int(input())
dic = {}
x = 0
count = 0
while 1:
    x = (x * 10 + 7) % K
    count += 1
    if x == 0:
        print(count)
        exit()
    if x in dic:
        print(-1)
        exit()
    dic[x] = 1

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

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

Solution (Python):
k=int(input())
l=[0]*k
x=7%k
s=-1
for c in range(k):
    if x==0:
        s=c+1
        break
    if l[x]==1:
        break
    l[x]=1
    x=(10*x+7)%k
print(s)

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

cnt=1
Num=7%K
while cnt<=K:
  if K%2==0:
    print('-1')
    break
  if Num%K==0:
    print(cnt)
    break
  else:
    Num = (10*Num + 7)%K
    cnt+=1
else:
  print('-1')

Solution (Python):
import sys
K=int(input())
if K%2==0 or K%5==0:
    print('-1')
    sys.exit()
i=1
K=9*K
ans=10-K

while(1):
    if 7*(ans-1)%K==0:
        print(i)
        sys.exit()
    i+=1
    ans=ans*10%K

Solution (Python):
K = int(input())
A = 7 % K 

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

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

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

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

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

now = 7
cnt = 1
used = [False] * k
ten = 10
while not used[now % k]:
    if now % k == 0:
        print(cnt)
        exit()
    used[now % k] = True
    now = (now + ten * 7) % k
    ten = ten * 10 % k
    cnt += 1
print(-1)

Solution (Python):
K = int(input())
if K%2==0:
    print(-1)
elif K==1:
    print(1)
elif K==7:
    print(1)
else:
    if K%7==0:
        K = K//7
    a = 1
    cnt = 1
    ind = -1
    for i in range(K):
        a = (a*10)%K
        cnt += a
        if cnt%K==0:
            ind = i
            break
    if ind<0:
        print(-1)
    else:
        print(ind+2)

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

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

ans = -1
x = 7%k
for n in range(1,k+10):
    if x == 0:
        ans = n
        break
    x = (10*x+7)%k
print(ans)

Solution (Python):
def solve(K):
    cur = 0
    tens = 1
    for i in range(1_000_001):
        cur += 7 * tens
        cur %= K
        if cur == 0:
            return i + 1
        tens *= 10
        tens %= K
    else:
        return -1


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

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

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

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

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

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

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

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

Solution (Python):
import sys

k = int(input())

a = 0

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

Solution (Python):
K = int(input())
count = 1
mod = 7
answer = -1

for _ in range(K):
    if mod % K == 0:
        answer = count
        break
    count += 1
    mod = (mod * 10 + 7) % K

print(answer)

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

ok = False
for i in range(1, k+1):
   if i == 1:
      a = 7 % k
   else:
      anext = (a * 10 + 7) % k
      a = anext
   if a == 0:
      print(i)
      ok = True
      break

if not ok:
   print(-1)

Solution (Python):
import sys

k = int(input())

a = 0

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

print(-1)

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

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

Solution (Python):
def check7s(k):
    x = 7 % k
    for i in range(1, k + 1):
        if x == 0: return i

        x = (x * 10 + 7) % k
 
    return -1

K = int(input())
print(check7s(K))

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

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

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

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

Solution (Python):
K = int(input())
num = 0
for i in range(0,K+1):
    num = (num*10+7)%K
    if num==0:
        print(i+1,'\n')
        break
if num:
    print("-1\n")

Solution (Python):


import sys
sys.setrecursionlimit(300000)


def solve(K: int):
    cur = 0
    for i in range(K):
        cur += pow(10, i, K) * 7
        cur %= K
        if cur == 0:
            print(i + 1)
            return i + 1
    ret = -1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  
    solve(K)

if __name__ == '__main__':
    main()

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

Solution (Python):
k=int(input())
if k&1==0 or k%5==0:
  print(-1)
  exit()
elif 7%k==0:
  print(1)
  exit()
m=7
a=b=1
while(m>0):
  a=a*10%k
  m=(m+7*a)%k
  b+=1
print(b)

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

Solution (Python):
def resolve():
    k = int(input())
    x = 7 % k
    for i in range(1, k + 1):
        if x == 0:
            print(i)
            return
        x = (x * 10 + 7) % k

    print(-1)

resolve()

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

if(k%2 == 0 or k%5 == 0):
    print('-1')
else:
    if(k%7 == 0):
        k = k // 7
    num = 1
    ans = 1
    while(True):
        if(num%k == 0):
            print(ans)
            break
        else:
            num %= k
            num *= 10
            num += 1
            ans += 1

Solution (Python):
import sys
K=input()
if int(K)%2==0:
    print(-1)
    sys.exit()

S=int('7'*(len(K)))
ans=len(K)
K=int(K)
for i in range(10**6):
    if S%K==0:
        print(ans)
        break
    else:
        S=(S*10)%K+7
        ans+=1
else:
    print(-1)