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

Solution (Python):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


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

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

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

if __name__ == '__main__':
	main()

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(K):
    visited = [False] * K
    p = 7 % K
    for i in range(K):
        if p == 0:
            return i + 1
        if visited[p]:
            return - 1
        visited[p] = True
        p = (p * 10 + 7) % K


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


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



T1 = """
101
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
4
"""
T2 = """
2
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
-1
"""
T3 = """
999983
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
999982
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()

Solution (Python):













from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy



MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): 
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): 
    return reduce(math.gcd, numbers)

def combination(m,n): 
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): 
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def main():
    K = int(stdin.readline().rstrip())
    L = 0
    amari = 10
    if K % 2 == 0 or K % 5 == 0:
        print("-1")
    else:
        if K % 7 == 0:
            L = 9*K//7
        else:
            L = 9*K
        for i in range(1,1000000):
            if amari % L == 1:
                print(i)
                break
            else:
                amari = (amari % L) * 10
main()

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

    L = 9 * K // 7 if K % 7 == 0 else 9 * K
    if L % 2 == 0 or L % 5 == 0:
        return -1

    remainder = 1
    for n in range(1, L + 1):
        remainder = (10 * remainder) % L
        if remainder == 1:
            return n
    return -1

print(c_repsept())

Solution (Python):
k = int(input())
tens = 10
exist = False
count = 1

if k % 2 == 0:
  exist = False
elif k % 5 == 0:
  exist = False
else:
  if k % 7 == 0:
    L = 9 * k / 7
  else:
    L = 9 * k
  for i in range(9000000):
    if tens % L == 1:
      exist = True
      break
    tens = tens % L * 10 % L
    count += 1
    

if exist:
  print(count)
else:
  print(-1)

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

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

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

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

def main():
    K = int(input())
    
    if K%2==0 or K%5==0:
        print(-1)
        return
    
    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)
main()

Solution (Python):



import sys
K = int(input())
res = 0
surplus = 1

if K % 2 == 0 or K % 5 == 0:
    res = -1
else:
    if K % 7 == 0:
        K /= 7
    while True:
        res += 1
        surplus = (10 * surplus) % (9*K)
        if surplus == 1:
            break
print(res)

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

N = 1000000
x = 7 % K

for i in range(1, N+1):
    if x == 0:
        break
    x = (x * 10 + 7) % K

if i == N:
    i = -1

print(i)

Solution (Python):





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

        curr *= 10
        curr += 7
        curr %= K

    return -1



def main():
    K = int(input())
    a = solve(K)
    print(a)

if __name__ == '__main__':
    main()

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

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

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

def main():
    K = int(input())
    
    if K%2==0:
        print(-1)
        return
    
    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)
main()

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

if k % 2 == 0 or k % 5 == 0:
  print(-1)
else:
  if k % 7 == 0:
    k //= 7
  if k == 1:
    print(1)
  else:
    k *= 9
    i = 1
    num = 10
    while num % k != 1:
      num %= k
      num *= 10
      i += 1
    print(i)

Solution (Python):
import sys

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())

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

Solution (Python):
import sys

def main():
    K = int(sys.stdin.readline())
    
    if K%2==0:
        print(-1)
        return
    
    if K % 7:
        L = 9*K
    else:
        L = 9*K//7
    a = 1
    for i in range(1,L+1):
        a = (a * 10) % L
        if a == 1:
            print(i)
            return
    print(-1)
main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
res = f_inf


def resolve():
    k = int(input())
    x = 7 % k
    s = set()
    i = 1
    while x not in s:
        if x == 0:
            print(i)
            break
        s.add(x)
        x = (x * 10 + 7) % k
        i += 1
    else:
        print(-1)


if __name__ == '__main__':
    resolve()

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):
import sys
input = sys.stdin.readline


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

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

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

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

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

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

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

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

ans = -1
history = set()
b = 0

for i in range(K):
    b = (10 * b + 7) % K

    
    if b in history:
        break

    
    if b == 0:
        ans = i + 1
        break

    history.add(b)

print(ans)

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

Solution (Python):
def main():
    k = int(input())
    ans = 1
    n = 7%k
    a = [-1 for i in range(k)]
    while True:
        if n==0:
            print(ans)
            return
        if a[n]==-1:
            a[n] = 1
            ans += 1
            n = (n*10+7)%k
        else:
            print(-1)
            return

if __name__ == "__main__":
    main()

Solution (Python):
K = input()
K_1 = int(K[-1])
K = int(K) 

mod_ini = 7%K
mod = 0
cnt = 0

while True:
    if K%2 == 0 or K_1 == 5:
        print(-1)
        break
    
    cnt += 1
    mod = (mod*10 + 7)%K
    
    
    if mod == 0:
        print(cnt)
        break
    elif mod == mod_ini and cnt != 1:
        print(-1)
        break

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

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


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

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

    rest = [7 % k]

    for i in range(k):
        rest.append(rest[-1] * 10 % k)

    tmp = 0
    for i in range(k):
        if (tmp + rest[i]) % k == 0:
            print(i + 1)
            return
        else:
            tmp = (tmp + rest[i]) % k
    else:
        print(-1)
main()

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

Solution (Python):

import sys
k=int(input())
if k%2==0 or k%5==0:
  print(-1)
  sys.exit()
s=7
for i in range(k):
  m=s%k
  if m==0:
    print(i+1)
    break
  s=m*10+7

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

Solution (Python):
k = int(input())
if k % 2 == 0 or 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())

cnt = 1

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

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

K = int(readline())

cur = 0
mods = set()
cnt = 0
while True:
  cnt += 1
  
  cur *= 10
  cur += 7
  cur %= K
  if cur == 0:
    print(cnt)
    break
  if cur in mods:
    print(-1)
    break
  mods.add(cur)

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

x = 7 % k

s = [0] * k
i = 1

while s[x] == 0:
    if x == 0:
        print(i)
        exit()
    s[x] = 1
    x = (x * 10 + 7) % k
    i += 1

print('-1')

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

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

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

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

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

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

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

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

flg = [False]*K

tmp = 7 % K
cnt = 1
if tmp == 0:
    print(cnt)
    exit()
while True:
    tmp = (tmp*10+7)%K
    if flg[tmp]:
        print(-1)
        break
    else:
        cnt += 1
        if tmp == 0:
            print(cnt)
            break
        flg[tmp] = True

Solution (Python):
import sys
K = input()
if K[-1] == '2' or K[-1] == '4' or K[-1] == '5' or K[-1] == '6' or K[-1] == '8' or K[-1] == '0':
    print(-1)
    sys.exit()
K = int(K)
n = 7 % K
i = 1
while i <= K:
    if n == 0:
        print(i)
        sys.exit()
    n = 10 * n + 7
    n %= K
    i += 1
print(-1)

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

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

ans = 1
now = 7 % K
isvisited = set()

while now != 0:
    if now in isvisited:
        print(-1)
        exit()
    isvisited.add(now)
    now = (now * 10 + 7) % K
    ans += 1

print(ans)

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


def main(input, print):
    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(sys.stdin.readline, print)

Solution (Python):
import sys

K = int(input())

seven = 7
seven %= K
for i in range(K+2):
    if seven == 0:
        print(i+1)
        sys.exit()
    seven = seven * 10 + 7
    seven %= K

print(-1)

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

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

res = -1
count = 0
ai = 0
while(True):
    ai = (ai*10 + 7) % K
    count += 1
    if(ai == 0):
        res = count
        break

print(res)

Solution (Python):
import sys

K = int(input())

seven = 0
for i in range(K+2):
    seven += (7 * pow(10, i, K)) % K
    seven %= K    
    if seven == 0:
        print(i+1)
        sys.exit()

print(-1)

Solution (Python):
import sys

K = int(input())

seven = 0
for i in range(K+2):
    seven += (7 * pow(10, i, K)) % K
    seven %= K    
    if seven == 0:
        print(i+1)
        sys.exit()

print(-1)

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

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

print(-1)

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

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

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

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

Solution (Python):
k=int(input())
if k%2==0:
    print(-1)
    exit()
def solver(k):
    tmp=7%k
    cnt=1
    while cnt <= k:
        if tmp%k != 0:
            tmp=(tmp*10+7)%k
            cnt+=1
        else:
            return cnt
    return -1
        
print(solver(k))

Solution (Python):

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

Solution (Python):


import itertools
import collections
from decimal import Decimal





def main():
    n = int(input())
    nana = 7
    for i in range(n):
        if nana % n == 0:
            print(i+1)
            exit()
        nana = (nana * 10 + 7) % n
    print(-1)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


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


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Solution (Python):
k=int(input())
ans=7
ans2=10
prev=7
hbe=False
if ans%k==0:
    print(1)
    hbe=True
else:
    for i in range(0, k + 1, 1):
        ans=(7*ans2+prev)%k
        if ans%k==0:
            print(i+2)
            hbe=True
            break
        prev=ans
        ans2=(ans2*10)%k
if hbe==False:
    print(-1)

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


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

Solution (Python):
K = int(input())
if K%7 == 0:
  L = 9*K//7
else:
  L = 9*K

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

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

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

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

rem=1
for i in range(1,L+1):
    rem*=10
    rem=rem%L
    if rem==1:
        break
print(i)

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

def f(k):
  if k % 2 == 0 or k % 5 == 0:
    return -1    

  val = 7
  cnt = 1
  while cnt < 10 ** 6:
    val %= k
    if val % k == 0:
      break
    cnt += 1
    val = val * 10 + 7
  else:
    return -1
  return cnt
    
print(f(k))

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

f = 0
now = 0
a = [0] * k

for i in range(k):
    now = (now * 10 + 7) % k
    if(now == 0):
        print(i+1)
        f = 1
        break
    if(a[now] == 1): break
    a[now] = 1

if f == 0:
    print(-1)

Solution (Python):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    k = int(input())
    x = 7%k
    y = set()
    cnt = 1
    for i in range(k+1):
        if x == 0:
            print(cnt)
            exit()
        if x in y:
            print(-1)
            exit()
        y.add(x)
        x = (x*10+7)%k
        cnt += 1




if __name__=="__main__":
    main()

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy









def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

k = inp()

keta = len(str(k))
ans = -1
tmp = 0
for i in range(1000001):
    tmp = ((tmp + (7 * pow(10,i,k)) % k)) % k
    if tmp == 0:
        ans = i+1
        break

print(ans)

Solution (Python):
K = int(input())
l = [0 for i in range(K)]
r = 0
for i in range(K):
    r = (10*r+7)%K
    if r == 0:
        print(i+1)
        break
    elif l[r] != 0:
        print(-1)
        break
    else:
        l[r] = 1

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

k = 7
m = k%n
if m == 0:
    print(1)
    exit()
cnt = 1

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

Solution (Python):
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from fractions import Fraction
from itertools import combinations
from math import gcd
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    K = int(input())
    ss = set({})
    mod = 7 % K
    count = 1
    while True:
        if mod == 0:
            print(count)
            exit()
        if mod in ss:
            print(-1)
            exit()
        ss.add(mod)
        mod = (mod * 10 + 7) % K
        count += 1

if __name__ == '__main__':
    main()

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

x = 0

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

Solution (Python):
def f(k):
    r = 7%k
    i = 1
    s = set()
    while r not in s:
        if not r: return i
        i += 1
        s.add(r)
        r = (r*10 + 7)%k
    return -1

print(f(int(input())))

Solution (Python):
def f(k):
    r = 7%k
    s = set()
    for i in range(k):
        if not r: return i+1
        s.add(r)
        r = (r*10 + 7)%k
        if r in s: break
    return -1

print(f(int(input())))

Solution (Python):
import sys

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b

def solve():
    input = sys.stdin.readline
    K = int(input())
  
    N = 0
    for i in range(1, K + 1):
        N = (N * 10 + 7) % K
        if N == 0:
            print(i)
            break
    else:
        print(-1)
   
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
def f(k):
    r = 7%k
    i = 1
    s = set()
    while r not in s:
        s.add(r)
        if not r: return i
        r = (r*10 + 7)%k
        i += 1
    return -1

print(f(int(input())))

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

f=0
n=K

for i in range(10**6 + 1):
    if n == 0:
        f=1
        print(i)
        break
    n = ((n*10) + 7 ) % K
    
if f==0:
   print(-1)

Solution (Python):
x = int(input())
t = 7
amari = 0
flag = 0

for i in range(x):
    if t%x == 0:
        print(i+1)
        flag = 1
        break
    else:
        amari = t%x
        t = 7+(amari*10)


if flag == 0:
    print(-1)

Solution (Python):
def f(k):
    r = 7%k
    for i in range(k):
        if not r: return i+1
        r = (r*10 + 7)%k
    return -1

print(f(int(input())))

Solution (Python):



k = int(input())
ret = 1
res = 7%k
while res != 0 and ret <= k:
    res *= 10
    res += 7
    res %= k
    ret += 1
if res != 0:
    print(-1)
else:
    print(ret)

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

print(f(int(input())))

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

Solution (Python):
def Repsept():
    
    num = int(input())

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


if __name__ == '__main__':
    Repsept()

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

cnt = set()
k = 7%K
i = 1

while k not in cnt:
  if k == 0:
    print(i)
    exit()

  cnt.add(k)
  k = (10*k+7) % K
  i += 1

print(-1)

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

s = set()
x = 7 % K
i = 1
while x not in s:
	if x == 0:
		print(i)
		break
	else:
		s.add(x)
		x = (x * 10 + 7) % K
		i += 1
else:
	print(-1)

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

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

ans = -1
n = 10
for i in range(1, L):
    surplus = n % L
    if surplus == 1:
        ans = i
        break
    n = 10 * surplus
print(ans)

Solution (Python):

import sys 
from collections import defaultdict
sys.setrecursionlimit(10**6)
MOD = 10**9+7 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
K = int(readline())
cnt = 0
N = 7
for i in range(K+1):
    if N % K == 0:
        print(i+1)
        sys.exit()
    N = (N*10+7) % K
print(-1)

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

Solution (Python):

import sys
def main(K):
    m = 0
    for i in range(1, 10**6):
        m = (m * 10 + 7) % K
        if m == 0:
            print(i)
            return
    print(-1)

if __name__ == '__main__':
    input = sys.stdin.readline
    K = int(input())
    main(K)

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

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

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

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

flg = False
x = 7 % k
for i in range(1, k+2):
    if x == 0:
        flg = True
        break
    else:
        x = (10 * x + 7) % k
print(i) if flg else print(-1)

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

  a=((10*a)+7)%k
    
print(ans)

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



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

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

k=int(input())

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

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

i = 7 % k
cnt = 1
while i != 0:
    i = i * 10 + 7
    i %= k
    cnt += 1
print(cnt)

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

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

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

i = 1
r = 7 % K
R = {r}
while r != 0:
    i += 1
    r = (r * 10 + 7) % K
    if r in R:
        print(-1)
        exit()
    R.add(r)

print(i)

Solution (Python):
k=int(input())
num=1
L=0
ans=-1


if k%7==0:
	L=(9*k)/7
else:
	L=9*k




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

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

a = 7

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

Solution (Python):
K = int(input())
A = 7%K
Flag = False
for T in range(1,K+1):
    if A==0:
        Flag = True
        break
    else:
        A = (10*A+7)%K
print(['-1',T][Flag])

Solution (Python):
K = int(input())
x = 7 % K 
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
i = 0
while i < K:
  ans += 1
  x = (x * 10 + 7) % K
  
  
  if x == 0:
    print(ans)
    exit()
  i += 1
print('-1')

Solution (Python):
K = int(input())
x = 7 % K 
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
i = 0
while i < K:
  ans += 1
  x = (x * 10 + 7) % K
  
  
  if x == 0:
    print(ans)
    exit()
  i += 1
print('-1')

Solution (Python):
K = int(input())
x = 7 % K 
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
i = 0
while i < K:
  ans += 1
  x = (x * 10 + 7) % K
  
  if x == 7 % K:
    print('-1')
    exit()
  if x == 0:
    print(ans)
    exit()
  i += 1
print('-1')

Solution (Python):
k=int(input())
num=7%k
ans=-1

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

print(ans)

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

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

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

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

if k == 1:
    print(1)
    exit()

tmp = 7
for i in range(1, 10**7):
    tmp = (10 * tmp) % (9*k)
    if tmp == 7:
        print(i)
        exit()

print(-1)