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):
import datetime
import string
import re
import math

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

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

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

    tmp1 = 7 % K
    tmp2 = tmp1

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

    print(-1)


if __name__ == "__main__":
    main()

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

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

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

flag = 0
count = len(str(k))

if k % 2 == 0:
  print(-1)
  exit()
  
if str(k)[-1] == '5':
  print(-1)
  exit()

count = len(str(k))
test = int('7' * count)
amari = test % k
while True:
  if amari == 0:
    break
  else:
    amari = (amari * 10 + 7) % k
    count += 1
  
print(count)

Solution (Python):
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq

import bisect
import sys

sys.setrecursionlimit(10**6)


def bfs(s, n, node):
    
    check = [False for _ in range(n)]
    check[s] = True
    
    queue = deque([s])
    visited_num = 1

    
    
    color = [-1 for _ in range(n)]
    color[s] = 0

    while visited_num < n:
        
        if len(queue) == 0:
            
            
            return color

        now_vertex = queue.popleft()
        
        for next_vertex in node[now_vertex]:

            if check[next_vertex] == True:
                continue

            queue.append(next_vertex)
            check[next_vertex] = True

            
            color[next_vertex] = color[now_vertex]+1
            visited_num += 1

    return color


mod = 10**9+7



def ceil(x, y): return (x+y-1)//y
def input_list(): return list(map(int, input().split()))


n = int(input())
num = 10**6
cal = [(7*pow(10, i, n)) % n for i in range(num)]


c = 0
for i in range(num):
    c += cal[i]
    c %= n
    if c == 0:
        print(i+1)
        exit()

print(-1)

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

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

a = 7
p = {}
ans = 0

while True:
    t = a % K
    ans += 1
    if t == 0:
        print(ans)
        break
    if t in p:
        print(-1)
        break
    a = 10*t + 7
    p[t] = 1

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

Solution (Python):
k = int(input())
import sys
i = 1
amari = 7%k
ama = 7%k
while True:
    if amari%k ==0:
        print(i)
        sys.exit()
    else:
        ama = (ama*10)%k
        amari += ama
        i +=1
    if i == k+1:
        break
print(-1)

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

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

a=7
ans=1
while(1):
  if a%k==0:
    print(ans)
    sys.exit()
  else:
    a=a%k
    a=a*10+7
    ans=ans+1

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

Solution (Python):



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


k = int(input())
n = 7
flag = False
for i in range(k):
    if n % k == 0:
        print(i+1)
        flag = True
        break
    else:
        n = n*10+7
        n %= k
if not flag:
    print(-1)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

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

Solution (Python):
def solve(k):
    if(k%2==0 or k%5==0):
        return -1
    if(k%7==0):
        k//=7
    amari=1
    now=1
    for i in range(k+1):
        if(now%k==0):
            return i+1
        amari*=10
        amari%=k
        now+=amari
        now%=k
    return -1

k=int(input())

print(solve(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()
print(-1)

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

Solution (Python):
k=int(input())
curr=7
curr=curr%k
count=1
if(k%2==0 or k%5==0):
	print(-1)
else:
	for i in range(1,k+1):
		if(curr==0):
			print(count)
			break
		else:
			curr=(curr*10+7)%k
			count+=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%2==0:
    print(-1)
    exit()


now=0
count=0
N=0
flag=False
while True:
    now+=(7*pow(10,count, K))%K
    now%=K
    
    if not flag:
        N+=7*10**(count)
    if N>=K:
        flag=True
    
    if now==0 and flag:
        print(count+1)
        exit()
    count+=1
    if count>10**6:
        break


print(-1)

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

table = [0] * k
a = math.floor(math.log10(k))

num = 7
base = 1
result = 1
for i in range(a):
  base *= 10
  result += 1
  num += base * 7
if(num < k):
  base *= 10
  result += 1
  num += base * 7

div = (num - k) % k

while(div != 0 and table[div]==0):
  table[div] = 1
  div = (div * 10 + 7) % k
  result += 1

if(div == 0):
  print(result)
else:
  print(-1)

Solution (Python):
def main():
    K = int(input())
    ans = 0
    prev = 0
    seen = set()
    tenmod = 10 % K
    sevenmod = 7 % K
    for  i in range(K):
        m = ((tenmod * prev) + sevenmod ) % K
        if m == 0:
            print(i+1)
            break
        if m in seen:
            print(-1)
            break
        seen.add(m)
        prev = m
    
if __name__ == "__main__":
    main()

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

Solution (Python):
K = int(input())
Ali = []

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

Solution (Python):
k=int(input())
a="0"
l=[]
if k%2==0:
  print("-1")
else:
  for i in range(k):
    a=a+"7"
    b=int(a)
    b=b%k
    if b==0:
      ans=i+1
      l.append(ans)
      print(ans)
      break
    a=str(b)
  if l==[]:
    print("-1")

Solution (Python):
import sys
k=int(input())
A=[0]*k
C=[7%k]
A[7%k]=1
if 7%k==0:
    print(1)
    sys.exit()
while True:
    now=(C[-1]*10+7)%k
    if A[now]==1:
        print(-1)
        break
    A[now]=1
    C.append(now)
    if now==0:
        print(len(C))
        break

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

Solution (Python):
import time
K=int(input())
mod=7%K

if 7%K==0:
  print(1)
  exit()
ans=1
now=time.time()
while 1:
  ans+=1
  mod=(mod*10+7)%K
  if mod==0:
    print(ans)
    break
  if time.time()-now>=1.8:
    print(-1)
    break

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

d=7%k
c=-1
for i in range(10**6+10):
    if d==0:
        c=i+1
        break
    d=(d*10+7)%k

    
print(c)

Solution (Python):
K = int(input())
a = 7
cnt = 1
while a % K != 0:
    a = a * 10 + 7
    a = a % K
    cnt += 1
    if cnt == 10**6 + 10:
        break

if cnt == 10**6 + 10:
    print(-1)
else:
    print(cnt)

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

Solution (Python):
import math
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

K = int(input())

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

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

a = 7
counter = 1
flag = 0

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

if(flag == 0):
    print("-1")

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

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

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

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

sm=0
work=7
for i in range(1,5*n):
    sm+=work
    while sm>=n:
        sm-=n
    if sm==0 :
        print(i)
        break
    work*=10
    work%=n
else : print(-1)

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

def main(K):
  cnt = 1
  amari = 0
  while True:
    amari *= 10
    amari += 7
    amari %= K
    if amari == 0:
      return cnt
    else:
      cnt += 1
  

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

Solution (Python):


import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def divisor(n):
    i = 1
    table = [7, ]
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(7*i)
            table.append(n // i)
            table.append((n//i)*7)
        i += 1
    table = set(table)
    return table


def main():
    k = ni()
    a = 0
    for i in range(1, 10**6+1):
        a = (10*a + 7) % k
        if a == 0:
            print(i)
            quit()
    print(-1)

if __name__ == "__main__":
    main()

Solution (Python):
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    
    t=1
    for _ in range(t):
        n=int(input())
        num=7
        ans=0
        ls={}
        while 1:
            if num%n==0:
                ans+=1
                break
            else:
                if num%n in ls:
                    ans=-1
                    break
                ls[num%n]=1
                st=num%n
                st=str(st)+"7"
                
                ans+=1
                num=int(st)
        print(ans)






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:
	print(-1)
	quit()

sevens = 7
for i in range(1000000):
	if sevens % k == 0:
		print(str(i+1))
		quit()
	else :
		sevens = (sevens % k) * 10 + 7

print(-1)
quit()

Solution (Python):
K = int(input())
count = 1
rem = 7 % K

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0 and count <= K:
        count += 1
        rem += 7 * pow(10, count-1, mod=K) % K
    if count <= K:
        print(count)
    else:
        print(-1)

Solution (Python):
import sys
input = sys.stdin.readline
K = int(input())
if K % 3 == 0: K *= 9
for x in range(1, K + 1):
  if 7 * (pow(10, x, K) - 1) % K == 0:
    print(x)
    break
else: print(-1)

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

his = set()
cnt = 0
x = 7
while True:
    cnt += 1
    r = (x % K)
    if r == 0:
        print(cnt)
        break
    if r in his:
        print(-1)
        break
    his.add(r)
    x = r * 10 + 7
exit()

Solution (Python):
num = int(input())
val = 7
cnt = 1
while True:
    val %= num
    if cnt >= 10 ** 6: 
        cnt = -1
        break
    if val == 0: break
    val *= 10
    val += 7
    cnt += 1
print(cnt)

Solution (Python):
K = int(input())
amari = 0
res = set()
tmp = 7
flag = False
for i in range(10**6):
    if i == 0:
        if tmp % K == 0:
            flag = True
        else:
            tmp = tmp % K
            res.add(tmp)
            amari += tmp
    else:
        tmp = (tmp * 10) % K
        amari += tmp
        amari = amari % K
        if amari == 0:
            flag = True
    if flag:
        break
if flag:
    print(i + 1)
else:
    print(-1)

Solution (Python):
k=int(input())
if k%2==0 or k%5==0:
  print(-1)
  exit()
  
le=len(str(k))
p=int(''.join(['7']*le))
i=0
s=p%k
while True:
  if s==0:
    print(le+i)
    exit()
  else:
    s+=7*pow(10,le+i,k)
    s%=k
    i+=1

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

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    K = I()

    if K % 2 == 0 or K % 5 == 0:
        print(-1)
    else:
        rem = 7 % K
        ans = 0
        while rem != 0:
            rem = rem * 10 + 7
            rem %= K
            ans += 1

        print(ans + 1)

if __name__ == '__main__':
    resolve()

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

Solution (Python):
K = int(input())
M = 10**6+1

def solve():
    count = 1
    res = 0
    c = 7 % K
    while count < M:
        res = (res * 10) % K
        res = (res + c) % K
        if res == 0:
            return count
        count += 1
    return -1

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

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


def readstr():
    return input().strip()


def readint():
    return int(input())


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


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


def main():
    K = readint()
    if not K % 2:
        print(-1)
    elif not 7 % K:
        print(1)
    else:
        d = 7 % K
        s = set()
        for i in range(1, 10 ** 6 + 1):
            s.add(d)
            d = (d * 10 + 7) % K
            if not d:
                print(i + 1)
                sys.exit()
            elif d in s:
                print(-1)
                sys.exit()
        print(-1)


if __name__ == "__main__":
    main()

Solution (Python):
K = int(input())
map = {0: True}
cnt = 1
nana = 7 % K
md = 7 % K
while md not in map:

    cnt += 1
    map[md] = True
    md = (10 * md + nana) % K
    
if md == 0:
    print(cnt)
else:
    print("-1")

Solution (Python):
import sys

k=int(input())

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

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

Solution (Python):
a=int(input())
a_list=[]
amari=0
count=0
flag=False
if a%2==0 or a%5==0 :
  flag=True
else :

  while(True) :
    k=(amari*10+7)%a
    if k==0 :
      count+=1
      break
    else :
      count+=1
      amari=k



if flag :
  print('-1')
else :
  print(count)

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

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

Solution (Python):

import sys
input = lambda: sys.stdin.readline().strip()
k = int(input())
x = 0
for i in range(1, k + 1):
    x *= 10
    x += 7
    x %= k
    if x == 0:
        print(i)
        exit(0)
print(-1)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]





K = ii()
n = 7 % K
cnt = 1
flag = [0] * K
flag[n] = 1

while True:
    if n == 0:
        print(cnt)
        exit()
    n = (n * 10 + 7) % K
    if flag[n]:
        print(-1)
        exit()
    cnt += 1
    flag[n] = 1

Solution (Python):
k=int(input())
t = []
x=1
lim=1000005
mod = 0
ans=0
for i in range(lim):
	ans+=1
	t+=[x%k]
	x = (x%k * 10%k)%k
	mod = (mod + (7%k * t[i])%k)%k
	if mod == 0:
		break
if mod==0: print(ans)
else: print(-1)

Solution (Python):
k = int(input())
if(k==1 or k==7):
    print(1)
    exit()
if(k%2==0):
    print(-1)
    exit()
x = 7
ans = None
for i in range(2,10**6+5):
    nex_x = 10*x+7
    nex_x = nex_x%k
    if(nex_x==0):
        ans = i
        break
    x = nex_x
    
if(ans is None):
    print(-1)
else:
    print(ans)

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

Solution (Python):
k = int(input())
if k == 1 or k == 7:
    print(1)
    exit()
count = 1
tmp = 7
s = [0 for i in range(k+8)]
while True:
    if s[tmp] != 0:
        print(-1)
        exit()
    s[tmp]+=1
    tmp*=10
    tmp+=7
    tmp %= k
    count+=1
    if tmp == 0:
        print(count)
        exit()

Solution (Python):
import math
n = int(input())
now = 0
cnt =0
while cnt<n:
	now = now*10+7
	now =now%n
	if now%n==0:
		break
	cnt =cnt+1
if cnt==n:
	print(-1)
else:
	print(cnt+1)

Solution (Python):
k=int(input())
ans=int(0)
n=0
dp=[0]*(1000000)
f=int(0)
for i in range(0,1000000):
    ans+=1
    n=n*10+7
    if(n%k==0):
        break
    n=n%k
    if(dp[n]):
        f=1
        break
    else:
        dp[n]=1
if(f):
    print("-1")
else:
    print(ans)

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

k = int(input())

res = 1
a = 7%k
p = 7

d = set()

while True:
    if a == 0:
        print(res)
        exit()
    p = p*10%k
    a = (a+p)%k
    res += 1
    if a in d:
        print(-1)
        exit()
    d.add(a)
print(-1)