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):
def solve(n):
  s = set()
  i = 1;
  x = 7 % n
  while (not (x in s)):
    if x == 0:
      return i;
    s.add(x)
    x = x * 10 + 7;
    x %= n;
    i += 1
  return -1

if __name__ == '__main__':
  n = int(input())
  if n == 2 or n == 5:
    print(-1)
  else:
    print(solve(n))

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

A = 7
ans = 1

while ans <= K:
  if K % 2 == 0 or K % 5 == 0:
    print('-1')
    break
  if A % K == 0:
    print(ans)
    break
  A = (A * 10 + 7) % K
  ans = ans + 1

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

visited = set()
remainder = 7
counter = 1

while True:
    remainder = remainder % K
    if remainder in visited:
        print(-1)
        exit()
    if remainder == 0:
        print(counter)
        exit()
    else:
        visited.add(remainder)
        remainder = 10 * remainder + 7
    counter += 1

Solution (Python):

"""
数列777...は奇数故，Kが偶数だったら×

"""
from numba import njit


@njit(cache=True)
def func(a, b):
    return a * b


def main():
    import sys
    input = sys.stdin.readline

    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)


if __name__ == '__main__':
    main()

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

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

Solution (Python):



K = int(input())

mod = 7 % K

res = {}

i = 1

while not mod in res:
    if mod == 0:
        print(i)
        exit()

    res[mod] = 1
    mod = (mod * 10 + 7) % K
    i += 1

print(-1)

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

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

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

x = 7

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

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

    print(cnt)

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

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

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

a = 7 % K

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

print(-1)

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

Solution (Python):
import sys
import math
import time
import numpy
sys.setrecursionlimit(int(1e6))

def dprint(*args):
    pass

k = list(map(int, input().split()))[0]

s = set()
i = 1
x = 7 % k

while(not (x in s)):
    if (x == 0):
        print(i)
        exit()
    s.add(x)
    x = (x*10+7)%k
    i = i + 1

print(-1)

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

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

print(ans)

Solution (Python):
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    from time import perf_counter
    s = perf_counter()
    ans = 1
    num = 7
    K = II()
    if K % 2 == 0:
        print(-1)
        return
    while perf_counter() - s < 1.9:
        if num % K == 0:
            print(ans)
            return
        else:
            num = (num*10+7)%K
            ans += 1
    print(-1)
    dbg(len(str(num)))
    return
        


    
main()

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

r = 0
cnt = 0
x = 0
while x < 10 ** 6 + 1:
    r = r * 10 + 7
    r %= K

    if r % K == 0:
        print(cnt + 1)
        exit()

    cnt += 1
    x += 1

print(-1)

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):
k = int(input())
mod = 7%k
for i in range(k):
    if mod%k == 0:
        print(i+1)
        exit()
    mod = (mod*10+7) % k
print(-1)

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

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

if k == 1 or k == 7:
    print(1)

elif k % 2 != 0 and k % 5 != 0:
    if k % 7 == 0:
        l = 9 * k // 7
    else:
        l = 9 * k

    m = 10 % l
    for i in range(1,k + 3):
        if m * 10 % l == 1:
            print(i + 1)
            break
        else:
            m = m * 10 % l

else:
    print(-1)

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

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

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


if __name__ == '__main__':
    main()

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

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

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

num = 7
cnt = 1
for i in range(k):
    if num % k == 0:
        break

    cnt += 1
    num = (num * 10 + 7) % k

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

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

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

go = 0
keta = len(str(k))

for i  in range(10**1000000):
    if k % 2 ==0:
        print(-1)
        break
    if k % 5==0:
        print(-1)
        break
    else:
        go =(go*10+7) %k
        if go ==0:
            print(i+1)
            break

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

nana = 7
count = 1

mod = 7 % K 

past = {mod}

while mod != 0:
  mod = (mod * 10 + 7) % K
  if mod in past:
    break
  past.add(mod)
  count += 1
  
if mod == 0:
  print(count)
else:
  print(-1)

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

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

mod=1
ans=-1
for i in range(1,L+1):
    mod=(mod*10)%L
    if mod%L==1:
        ans=i
        break

print(ans)

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

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

print(f(k))

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

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

def main():
    k = int(input())
    ans = 1

    if k % 2 == 0 or k % 5 == 0:
        print(-1)
    else:
        a = 7
        while 1:
            if a % k == 0:
                print(ans)
                break
            else:
                a = (a % k) * 10 + 7
                ans += 1
if __name__ == '__main__':
    main()

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

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

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

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

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

  L = 9 * K
  if K % 7 == 0:
    L = int(K / 7 * 9)

  target = 10
  for i in range(1, L+1):
    mod_L = target % L
    
    if mod_L == 1:
      print(i)
      return True
    target = mod_L*10

  print(-1)

if __name__ == "__main__":
  resolve()

Solution (Python):


k = int(input())
if k % 2 == 0:
    print(-1)
elif k % 5 == 0:
    print(-1)
else:
    c = 7
    count = 1
    while True:
        if c % k == 0:
            print(count)
            break
        else:
            c = (10 * c + 7) % k
            count += 1

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

Solution (Python):
K=int(input())
if K%2==0:
    print(-1)
else:
    if K%7==0:
        L=9*K//7
    else:
        L=9*K
    rest=10%L
    for i in range(1,L+1):
        if rest==1:
            print(i)
            exit()
        else:
            rest=(rest*10)%L
        if i==L and rest!=1:
            print(-1)

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

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

if ((K & 1 == 0) or (s[-1] == "5")):
  print(-1)
else:
  if K % 7 == 0:
    L = 9 * K / 7
  else:
    L = 9 * K

  i = 1
  r = 10
  while True:
    r = r % L
    if r == 1:
      print(i)
      break
    r *= 10
    i += 1

Solution (Python):
import sys

k=int(input())
if k%2==0:
  print(-1)
  sys.exit(0)
c=1
m=7%k
while 1:
  if m==0:
    print(c)
    sys.exit(0)
  if c>k+1:
    print(-1)
    sys.exit(0)
  m=m*10+7
  m%=k
  c+=1

Solution (Python):
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

K = INT()

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

Solution (Python):

k=int(input())
a=set()
count=1
if k%2==0:
    print(-1)
else:
    
    ai=7%k
    while 1:
        if ai==0:
            print(count)
            break
        elif ai in a:
            print(-1)
            break
        else:
            a.add(ai)
            ai=(ai*10+7)%k
            count+=1

Solution (Python):


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

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

    x = 7
    first = True
    flag = False
    for i in range(1000000):
        if(first):
            x = 7
            first = False
        else:
            
            x = (x * 10)%K + 7%K
        
        if(x % K == 0):
            print(i+1)
            flag = True
            break
    
    if(flag != True):
        print(-1)


if __name__ == "__main__":
    main()

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

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

print(func(K))

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

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

Solution (Python):






import io
import sys
import math


_DEB = 0   

_INPUT = """\
999983
"""
_EXPECTED = """\
4

"""
if _DEB:
    sys.stdin = io.StringIO(_INPUT)
    print("!! Debug Mode !!")

def logd(str):
    if _DEB: print(f"[deb] {str}")



k = int(input())


def solve():
    
    ans=-1
    mod_set=set()
    modx=10**9+7
    i=1
    n7=7%k
    while True:
        if n7==0:
            ans=i
            break
        if n7 in mod_set:
            break
        mod_set.add(n7)
        
        n7=(n7*10+7)%k
        i+=1
    
    ans = str(ans)
    print(ans)
    return ans


if __name__ == "__main__":
    ans = solve()

    
    if _DEB:
        if _EXPECTED.strip() == ans.strip(): print("\n!! Success !!")
        else: print(f"\n!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

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

def solve():
    if 7%k == 0:
        return 1
    val = 7
    for i in range(2, k + 1):
        val = val*10 + 7
        val = val%k
        if val == 0:
            return i

    return -1

print(solve())

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

l = 9 * k
if k % 7 == 0:
    l //= 7

ans = 1
num = 10
while True:
    if num % l == 1:
        break
    num = (num % l) * 10
    ans += 1
print(ans)

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

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

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

Solution (Python):
from collections import defaultdict 
import sys
import math 

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n = int(input())

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

Solution (Python):


def main():
    K = int(input())
    if K % 7 == 0:
        L = 9 * K / 7
    else:
        L = 9 * K
    if L % 2 == 0 or L % 5 == 0:
        ans = -1
    else:
        i = 1
        tmp = 10
        while True:
            tmp %= L
            if tmp == 1:
                ans = i
                break
            i += 1
            tmp *= 10

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 in [0, 2, 4, 5, 6, 8]:
        print(-1)
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            elif tmp // 10 % 10 == 8:
                num = 9
            elif tmp // 10 % 10 == 9:
                num = 8
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
k=int(input())
v=[1]*k
if k==1 or k==7:
  print(1)
  exit()
m=7%k
v[m]=0
for i in range(k):
  m=(10*m+7)%k
  if m==0:
    c=i+2
    break
  elif v[m]:
    v[m]=0
  else:
    c=-1
    break
print(c)

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

Solution (Python):

import sys

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 == 2 or k % 10 == 4 or k % 10 == 5 or k % 10 == 6 or k % 10 == 8 or k % 10 == 0:
        print(-1)
        exit()
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            elif tmp // 10 % 10 == 8:
                num = 9
            elif tmp // 10 % 10 == 9:
                num = 8
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break

if __name__ == '__main__':
    main()

Solution (Python):

import sys

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 == 2 or k % 10 == 4 or k % 10 == 5 or k % 10 == 6 or k % 10 == 8 or k % 10 == 0:
        print(-1)
        exit()
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            elif tmp // 10 % 10 == 8:
                num = 9
            elif tmp // 10 % 10 == 9:
                num = 8
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 5 * 10 ** 7:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    K = int(input())
    Kstr = str(K)
    
    if Kstr[-1] in ('0','2','4','6','8','5'):
        print(-1)
    else:
        if K%7 == 0:
            L = (9*K)/7
        else:
            L = 9*K
        S = 10
        for i in range(1,100000000000):
            S = S%L
            if S == 1:
                print(i)
                break
            S = S*10
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    K = int(input())
    Kstr = str(K)
    
    if Kstr[-1] in ('0','2','4','6','8','5'):
        print(-1)
    else:
        if K%7 == 0:
            L = (9*K)/7
        else:
            L = 9*K
        S = 10
        for i in range(1,6000000):
            S = S%L
            if S == 1:
                print(i)
                break
            S = S*10
    
if __name__ == '__main__':
    main()

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


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

print(i+1)

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

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

val = 7
idx = 1

while True:
    if val % k == 0:
        break
    else:
        idx += 1
        val = (val * 10 + 7) % k

print(idx)

Solution (Python):
if __name__ == '__main__':
    k = int(input())

    if k % 2 == 0 or k % 5 == 0:
        print('-1')
    else:
        mod_list = [7 % k]
        if mod_list[-1] == 0:
            print(1)
        else:
            for i in range(1000000):
                mod_list.append((mod_list[0] + mod_list[-1] * 10) % k)
                if mod_list[-1] == 0:
                    break
            print(len(mod_list))

Solution (Python):
K = int(input())
a = ""
ans = 0
amari = 10

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

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

    for p in range(10**6):
        if amari % L == 1:
            print(p+1)
            break
        else:
            amari = (amari*10)%L

Solution (Python):
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue



sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))





def main():
    k = ni()

    m = 0
    for i in range(10 ** 6 + 1):
        tmp = 7 * pow(10, i, k)
        m = (m + tmp) % k
        if m == 0:
            print(i + 1)
            exit(0)

    print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
k=int(input())
if (k%2)*(k%5)==0: print(-1)
else:
    i=1
    x=7
    while x%k:
        x=(x*10+7)%k
        i+=1
    print(i)

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

r = 7 % k
ans = 1
cnt = [0] * (k+1)
while r != 0:
  cnt[r] = 1
  r *= 10
  r += 7
  r %= k
  ans += 1
  if cnt[r]:
    ans = -1
    break

print(ans)

Solution (Python):
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue



sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))





def main():
    k = ni()

    m = 0
    for i in range(10 ** 6 + 1):
        tmp = 7 * pow(10, i, k)
        m = (m + tmp) % k
        if m == 0:
            print(i + 1)
            exit(0)

    print(-1)


if __name__ == '__main__':
    main()

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

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

else:
    if k % 7 == 0:
        d = (9 * k) // 7
    else:
        d = 9 * k
    
    res = 10

    for i in range(1, 100000000):
        if res % d == 1:
            print(i)
            exit()
        else:
            res = (res % d) * 10
    print(-1)

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

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):
def main():
  r=input()
  l=len(r)-1
  k = int(r)
  s=0
  for i in range(0,l):
    s=(s*10+7)
  for i in range(l,k):
    s=(s*10+7)%k
    if s==0:
      print(i+1)
      exit()
  print(-1)
main()

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

Solution (Python):
import sys
k = int(sys.stdin.read())
if k==2:
  print(-1)
  sys.exit()
value = 0
index = 0
while index < 1000000:
  index += 1
  value = (value*10+7)%k
  if value == 0:
    print(index)
    sys.exit()

print(-1)

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

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

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_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 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]*K
checked[mo] = 1
while mo != 0:
    mo = 10*mo + 7
    mo %= K
    p += 1
    if checked[mo]:
        print(-1)
        break
    checked[mo] = 1
else:
    print(p)