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:
    exc = 0
    for i in range(1, 10 ** 8):
        exc = exc * 10 + 7
        exc = exc % k
        if exc % k == 0:
            ans = i
            break
    print(ans)

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

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

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

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

print("-1")

Solution (Python):
k = int(input())
start = 7 % k
ans = start
con = 1

if k % 2 == 0 or k % 5 == 0:
  print("-1")
  exit()
while True:
  if ans == 0:
    print(con)
    break
  else:
    con += 1
    ans = ans * 10 + 7
    ans = ans % k
    if ans == start:
      print("-1")
      break

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

powlis = [7*pow(10, i, K) for i in range(K)]
for i in range(K-1):
    powlis[i+1] = (powlis[i] + powlis[i+1]) % K
powlis[0] %= K


try:
    print(powlis.index(0) + 1)
except:
    print(-1)

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

Solution (Python):
K = int(input())
import sys
num = 0
for n in range(K):
  num = num * 10 + 7
  if num % K == 0:
    print(n+1)
    break
  num = num % K
else:
  print(-1)

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

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

i = 7%K
se = set([i])
cnt = 1
while True:
  if i == 0:
    print(cnt)
    break
  cnt += 1
  i = (i*10 + 7)%K
  if i in se:
    print(-1)
    break
  else:
    se.add(i)

Solution (Python):
k = int(input())
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)
        break
else:
    print(-1)

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

Solution (Python):
mod = int(input())
a = {}
b = int(0)
flag = int(0)
ans = int(0)
for i in range(mod):
  b = b * 10 + 7
  b = b % mod
  if b == 0:
    flag = 1
    ans = int(i) + 1
    break
  else:
    pass

if flag == 1:
  print(ans)
else:
  print("-1")

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

start = j = 7 % K
count = 1


while True:
    
    if j == 0:
        print(count)
        exit()
        
    j = 10 * j + 7
    j = j % K
    count += 1
    
    
    if j == start:
        print(-1)
        exit()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    K = int(readline())
    a = 0
    ans = 0
    for _ in range(K+1):
        a = 10*a+7
        a %= K
        ans += 1
        if a%K == 0:
            break

    if ans == K+1: 
        print(-1)
    else:
        print(ans)
if __name__ == '__main__':
    main()

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

num = 7 % k
ans = 1
mod = [0 for _ in range(k)]
mod[num] = 1
while(num):
    num = (num * 10 + 7) % k
    if mod[num] > 0:
        ans = -1
        break
    ans += 1
    mod[num] += 1

print(ans)

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

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

ans=1
num=7
while num%k!=0:
  num=10*num+7
  num%=k
  ans+=1

print(ans)

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

seen = set()
extra = 7 % K
cnt = 1
seen.add(extra)
while extra != 0:
    extra = (extra * 10 + 7) % K
    if extra in seen:
        print(-1)
        exit()
    seen.add(extra)
    cnt += 1

print(cnt)

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

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

from collections import defaultdict
def main():
    k = int(input())
    if k % 2 == 0:
        print(-1)
        sys.exit()
    rems = defaultdict(int)
    n = 7 % k
    next_digit = 70 % k
    r = 1
    while True:
        if n == 0:
            print(r)
            sys.exit()
        elif rems[n]:
            print(-1)
            sys.exit()
        else:
            rems[n] = 1
            n += next_digit
            n = n % k
            next_digit = (next_digit * 10) % k
            r += 1
if __name__ == '__main__':
    main()

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

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

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

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

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

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

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

Solution (Python):



import sys

K = int(input())

a = 7 % K

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

Solution (Python):
from sys import stdin

input = stdin.readline
import math

def solve():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    cnt = 1
    cur = 7
    while True:
        r = cur % k
        if r == 0:
            print(cnt)
            break
        cur = r * 10 + 7
        cnt += 1

if __name__ == '__main__':
    solve()

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

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

print(ans)

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

ans = -1

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

Solution (Python):

K = int(input())


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

else:
    seen = set()
    ans = 1
    num = 7
    while ans <= K:

        mod = num % K
        if mod in seen:
            ans = -1
            break
        else:
            seen.add(mod)
        
        if mod == 0:
            break
        else:
            num = mod * 10 + 7
            ans += 1
    
    print(ans)

Solution (Python):

    
    


import sys, os.path


    
    

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))



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

Solution (Python):


k = int(input())

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

Solution (Python):
k = int(input())
x = 7 % k
i = 1
set = set()
is_there = False

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

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

a=[7 % K]
for i in range(1, K):
  a.append((10*a[i-1] + 7) % K)

flag = False
for i in range(len(a)):
  if a[i] == 0:
    print(i+1)
    flag = True
    break
if not flag:
  print(-1)

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

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

Solution (Python):


K=int(input())

res=1
r=7%K
flg=(K%2==0 or K%5==0)
if flg:
    res=-1
while not flg:
    if not r:
        break
    r=(10*r+7)%K
    res+=1
print(res)

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

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

Solution (Python):
def main():
  K = int(input())
  ans = False
  if K % 2 == 0:
    print(-1)
    exit()
  cnt = 7 % K
  for i in range(1, K+1):
    if cnt == 0:
      ans = True
      print(i)
      exit()
    cnt = (10 * cnt + 7) % K
  if ans == False:
    print(-1)
    exit()
main()

Solution (Python):
def calc(k):
    cur = 7 % k
    for i in range(1, k + 1):
        if cur == 0:
            return i
        else:
            cur *= 10
            cur += 7
            cur %= k
    return -1


k = int(input())
print(calc(k))

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

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

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


for i in range(K):
    if seven[i] == 0:
        print(i+1)
        exit()
print(-1)

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

def cal(k):
    n = 7
    for i in range(1,10000000):
        if n % k == 0:
            return i
        else:
            n = (n *10 + 7) % k
    return -1

print(cal(k))

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

def cal(k):
    n = 7
    for i in range(1,10000000):
        if n % k == 0:
            return i
        else:
            n = (n *10 + 7) % k
    return -1

print(cal(k))

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

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

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

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

Solution (Python):
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

K = ri()

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

Solution (Python):
import sys

from collections import deque, Counter, defaultdict

import bisect
import heapq

import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

k = ri()
reses=[]
cnt = 1
tmp = 7
for i in range(k+1):
    res = tmp % k
    if res==0:
        print(cnt)
        sys.exit(0)
    tmp = res * 10 + 7
    cnt += 1
print(-1)

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

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

print(ans)

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

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

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

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)
else:
    pmo = 1
    for i in range(1, l + 1):
        mo = (pmo * 10) % l
        if mo == 1:
            print(i)
            break
        else:
            pmo = mo

Solution (Python):

"""
Created on Mon Sep 14 13:35:45 2020

@author: ezwry
"""

k = int(input())
a = 7

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

print(-1)

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

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

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

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

mod = 7
cnt = 0

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

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


k = I()
ans = -1
a = [0] * (k+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):
N=int(input())
num = 7
i=1
a=[]
prir1=1
while i<=N:
    xx=num%N
    if xx==0:
        print(i)
        prir1=0
        break
    num=10*xx+7
    i+=1
if prir1:
    print(-1)

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

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
k = I()

i = 0
value = 7%k
while i < k:
    if value == 0:
        print(i+1)
        exit()
    value = (10*value + 7)%k
    i += 1
print(-1)

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

Solution (Python):
k = int(input())
cnt = 0
mod = [0]
not_found = 1
while cnt<k+1:
    cnt+=1
    n = mod[-1]*10+7
    mod.append(n%k)
    if n % k == 0:
        not_found = 0
        print(cnt)
        break
if(not_found):
    print(-1)

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

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

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

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

Solution (Python):
K=int(input())
S=set()
ans=0

x=7%K
i=1
while True:
    if x==0:
        ans=1
        break
    if x in S:
        break
    else:
        S.add(x)
    x=(x*10+7)%K
    i+=1

print(i if ans else -1)

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

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

x = 7%K

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

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

if chk==0:
	print(-1)

Solution (Python):
def main():
    K = int(input())
    
    a_i = 7
    if a_i % K == 0:
        print(1)
        return

    for i in range(2, 10 ** 6+1):
        a_i = a_i * 10 + 7
        if a_i % K == 0:
            print(i)
            return
        a_i %= K
    print(-1)

main()

Solution (Python):
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


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

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

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

if flag:
    print(-1)

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

else:
  for i in range (1,k):
    x = (x*10+7)%k

    if x%k == 0:
      ans = i+1
      break

print(ans)

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

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

a = [0]*k
a[0] = 7 % k

for i in range(1, k):
    a[i] = (10*a[i-1]+7) % k

for i in range(k):
    if a[i] == 0:
        print(i+1)
        sys.exit()
print(-1)

Solution (Python):
import time
start=time.time()
k=int(input())
ans=0
x=k
for i in range(10**9):
  while x%10!=7:
    x+=k
    if time.time()-start>=1.9:exit(print(-1))
  x//=10
  if x==0:exit(print(i+1))

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

if k % 2 == 0 or k % 5 == 0:
    print(-1)
elif k == 1 or k == 7:
    print(1)
else:
    t = 2
    ex = 77
    for i in range(10 ** 8):
        if ex % k == 0:
            break
        ex = (ex % k) * 10 + 7
        t += 1
    print(t)

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

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

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

Solution (Python):
def main():
    K = int(input())
    mod = 7 % K
    mods = set([mod])
    if mod == 0:
        print(1)
        exit()
    ans = 1
    while True:
        ans += 1
        mod = (mod * 10 + 7) % K
        if mod == 0:
            print(ans)
            exit()
        elif mod in mods:
            print(-1)
            exit()
        else:
            mods.add(mod)


if __name__ == '__main__':
    main()

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

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



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

Solution (Python):
def main():
    k = int(input())
    if k & 0:
        print(-1)
        return

    r = 7 % k
    l = 0
    while r and l < k:
        r = (r * 10 + 7) % k
        l += 1

    print([l+1, -1][l == k])


if __name__ == '__main__':
    main()

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

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

num = 0

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

    num %= K

print(-1)

Solution (Python):
K = int(input())
id = 1
cnt = 7
while cnt < K:
    cnt = cnt * 10 + 7
    id += 1

visited = [0] * K
while True:
    remz = (cnt % K)
    if remz == 0:
        break
    visited[remz] += 1
    if visited[remz] > 1:
        id = -1
        break
    cnt = remz * 10 + 7
    id += 1

print(id)

Solution (Python):
k=int(input())
A=[0]*k
f=0
for i in range(k):
  if i==0:
    A[i]=7%k
  else:
    A[i]=(10*A[i-1]+7)%k
  
  if A[i]==0:
    f=1
    print(i+1)
    exit()
if not f:
  print(-1)

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

Solution (Python):
import sys

n=input()
test=list(set(n))

if len(test)==1 and test[0]=="7":
    print(len(n))
    sys.exit()
n=int(n)
if n==1:
    print(1)
    sys.exit()
if n%2 ==0:
    print(-1)
    sys.exit()

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

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

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

Solution (Python):
def calc(k):
    cur = 0
    for i in range(1, 10 ** 7):
        cur *= 10
        cur += 7
        cur %= k
        if cur == 0:
            return i

    return -1


k = int(input())
print(calc(k))

Solution (Python):
k = int(input())
a = [None for i in range(10**7) ]

ans = -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:
        ans = i
        break

print(ans)

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

maxV = (10**6)**2

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

print(-1)

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

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

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

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

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
  a = 10 % L
  check = False
  for i in range(L):
    a %= L
    if a == 1:
      print(i + 1)
      check = True
      break
    a *= 10
  if not check:
    print(-1)

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

print(-1)

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

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

extra = 7 % K


seen = set()
ans = 1

while extra not in seen:
    if extra == 0:
        print(ans)
        exit()
    seen.add(extra)
    extra = (extra*10 + 7) % K
    ans += 1
print(-1)

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

Solution (Python):




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

Solution (Python):

import sys
k=int(input())
s=0

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

Solution (Python):
K=int(input())
num=7
ans=-1
for n in range(pow(10,7)):
    if num%K==0:
        ans=n+1
        break
    shou=num//K
    num-=K*shou
    num=int(str(num)+'7')
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    if k % 7 == 0:
        max_k = 9*k//7
    else:
        max_k = 9*k
    if k %2 == 0 or k%5 == 0:
        print(-1)
    while keta < max_k:
        if mod == 0:
            print(keta)
            break
        mod = (mod*10 + 7)%k
        keta += 1


if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    if k % 7 == 0:
        max_k = 9*k//7
    else:
        max_k = 9*k
    if k %2 == 0 or k%5 == 0:
        print(-1)
    while keta < max_k:
        if mod == 0:
            print(keta)
            break
        mod = (mod*10 + 7)%k
        keta += 1


if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    if k % 7 == 0:
        max_k = 9*k//7
    else:
        max_k = 9*k
    while keta < max_k:
        if mod == 0:
            print(keta)
            break
        mod = (mod*10 + 7)%k
        keta += 1
    else:
        print(-1)


if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    if k % 7 == 0:
        max_k = 9*k//7
    else:
        max_k = 9*k
    while keta < max_k:
        if mod == 0:
            print(keta)
            break
        mod = (mod*10 + 7)%k
        keta += 1
    else:
        print(-1)


if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    while keta < 10**7:
        if mod==0:
            print(keta)
            break
        keta += 1
        mod = (mod*10 + 7)%k
    else:
        print(-1)


if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    while keta < 10**7:
        if mod==0:
            print(keta)
            break
        keta += 1
        mod = (mod*10 + 7)%k
    else:
        print(-1)


if __name__=='__main__':
    main()

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

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

Solution (Python):
k = int(input())
i = 0
s = 0
ans = -1

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

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())
 
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())
L = 0
if K % 7 == 0:
  L = 9*K//7
else:
  L = 9*K
  
ans = -1
s = 10
for i in range(1,L,1):
  if s % L == 1:
    ans = i
    break
  s = s % L * 10
print(ans)

Solution (Python):
k=int(input())
a=7
cnt=1
while cnt<=k+2:
    if a%k==0:
        print(cnt)
        flag=True
        break
    else:
        flag=False
        cnt+=1
        a=(10*a+7)%k
if not flag:
    print(-1)

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

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

Solution (Python):
K=int(input())
x=7
c=1
visited={7}
while x%K:
    x*=10
    x+=7
    x%=K
    c+=1
    z=x%K
    if z in visited:
        print(-1)
        exit()
    visited.add(x%K)
print(c)

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

t = 7
t %= k

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

"""
else:
for(while)文を
break文で抜ける（真）　⇒　実行しない
forのイテラブルを使い切る、whileが偽になる　⇒　実行する
"""

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

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

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

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    k = I()
    ans = -1
    s = 7%k
    if s==0:
        ans = 1
    else:
        for i in range(1,k):
            s = (s*10+7)%k
            if s == 0:
                ans = i+1
                break
    print(ans)

main()

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

a = [7%k]

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

for i in range(k):
    if a[i] == 0:
        print(i+1)
        exit()

print(-1)

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

a = [0] * K
a[0] = 7 % K

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

ans = -1
for i in range(K):
    if a[i] == 0:
        ans = i + 1
        break

print(ans)

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

    if k % 2 ==0:
        print(-1)
        return
    last = 0
    for i in range(1000000):
        if (last*10 + 7) % k == 0:
            print(i+1)
            return
        last = (last*10 + 7) % k
    print(-1)


if __name__ == '__main__':
    main()

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