Problem:
 Score : 300 points    Problem Statement Takahashi loves the number 7 and multiples of K .  Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots ? (Also see Output and Sample Input/Output below.)  If the sequence contains no multiples of K , print -1 instead.      Constraints  1 \leq K \leq 10^6  K is an integer.         Input Input is given from Standard Input in the following format:  K       Output Print an integer representing the position of the first occurrence of a multiple of K . (For example, if the first occurrence is the fourth element of the sequence, print 4 .)        Sample Input 1 101      Sample Output 1 4  None of 7 , 77 , and 777 is a multiple of 101 , but 7777 is.       Sample Input 2 2      Sample Output 2 -1  All elements in the sequence are odd numbers; there are no multiples of 2 .       Sample Input 3 999983      Sample Output 3 999982

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

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

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

INF = 10**8

w = 0
pows = 1
for i in range(INF):
  w += 7 * pows
  pows = pows * 10 % K
  w %= K
  if w == 0:
    print(i+1)
    break
  else:
    if w in hist:
      print(-1)
      break
    else:
      hist.add(w)

Solution (Python):









k = int(input())

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

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

Solution (Python):

K = int(input())

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

Solution (Python):
import sys, math
import io, os

from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
from decimal import Decimal
from fractions import Fraction

INF = float('inf')
mod = int(1e9)+7


k=int(data())
cnt=7
for i in range(1000001):
    if cnt%k==0:
        out(i+1)
        exit()
    cnt=(cnt*10+7)%k
out(-1)

Solution (Python):
k = int(input())
if k==1 or k==7:
  print(1)
elif k%2==0:
  print(-1)
else:
  cnt = 1
  pre = 7
  while(True):
    surp = (pre*10+7)%k
    cnt += 1
    if surp==0:
      break
    if cnt>1000000:
      cnt = -1
      break
    pre = surp
  print(cnt)

Solution (Python):
from math import gcd

x=int(input())
if gcd(x,10)!=1:
    print(-1)
    exit(0)

n=7
res=1
while n%x!=0:
    res+=1
    n*=10
    n+=7
    n%=x

print(res)

Solution (Python):



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

Solution (Python):
n=int(input())
if(n%2==0 or n%5==0):
    print(-1)
else:
    a=7 
    ans=1
    flag=1  
    while(flag):
        if(a%n==0):
            print(ans)
            flag=0
            break 
        else:
            ans+=1 
            s=str(a)
            s1='7'
            s2=int(s+s1)
            a=(int(s2))%n

Solution (Python):

N = int(input())

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

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

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

Solution (Python):
n=int(input())
if(n%2==0 or n%5==0):
    print(-1)
else:
    a=7 
    ans=1
    flag=1  
    while(flag):
        if(a%n==0):
            print(ans)
            flag=0
            break 
        else:
            ans+=1 
            s=str(a)
            s1='7'
            s2=int(s+s1)
            a=(int(s2))%n

Solution (Python):
k=int(input())
mod7 = 7%k
mod10= 10%k

mod = mod7
mod10times = mod7

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

    for i in range(2,2000000):
        mod10times = mod10times*mod10%k
        mod = mod10times+mod%k

        if  mod%k==0:
            break

    if i==1999999:
        print(-1)
    else:
        print(i)

Solution (Python):
K = int(input())
ans = 1
X = 7
cnt = K
while(cnt > 0):

    rem = X % K
    if rem == 0:
        print(ans)
        break
    else:
        ans += 1
        X = rem*10 + 7 
        cnt -= 1

if rem != 0:
    print(-1)

Solution (Python):
import sys
from math import sqrt, gcd, ceil, log

from collections import defaultdict, Counter, deque

input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))



def f(n):
	i = 0
	while n%10 == 7:
		n //= 10
		i += 1
	return((n,i))
def f2(a, b):
	return(b + [0, 10][a > b] - a)
	
def main():
	n = int(input()); 
	dic = defaultdict(int)
	for i in range(1, 10):
		for j in (1, 3, 7, 9):
			dic[(j, (i*j)%10)] = i

	if n%10 in (1, 3, 7, 9):
		t = n%10; ans = 0
		m, ans = f(n*(dic[(t, n%10)]))

		while m != 0:
			m += n*dic[(t, f2(m%10, 7))]
			m, y = f(m)
			ans += y
		print(ans)
	else:print(-1)





if __name__ == "__main__":
	main()

Solution (Python):
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

a=(int)(input())
flag=0

a=a*9

cnt=a
qq=a

for i in range(2,a+1):
   
    if i*i>a:
        break
    if qq%i==0:
       
        cnt=cnt/i*(i-1)
        while qq%i==0:
           
            qq=qq/i

if qq>1:
    cnt=cnt/qq*(qq-1)


qwq=(int)(cnt)
t=1

if a%2!=0 and a%5!=0:
    for i in range(1,a+1):
       
        if qwq%i!=0:
            continue
        
        if ((10**i-1)*7) % a == 0:
            flag=1
            print(i)
            break
if flag==0:
    print(-1)

Solution (Python):
k = int(input())
if k==1 or k==7:
  print(1)
elif k%2==0:
  print(-1)
else:
  cnt = 1
  pre = 7
  while(True):
    surp = (pre*10+7)%k
    cnt += 1
    if surp==0:
      break
    if cnt>1000000:
      cnt = -1
      break
    pre = surp
  print(cnt)

Solution (Python):
import sys

input = sys.stdin.readline

k = int(input())
if k == 7 or k == 1:
    print(1)
elif k % 2 == 0 or k % 5 == 0: print(-1)
else:
    if k % 7 == 0: k = k // 7
    mod = 9*k
    i = 1;
    result = 10;
    while result != 1:
        result = (result * 10) % mod
        i += 1
    print(i)

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

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

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

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

Solution (Python):
def main(k):
  if k % 2 == 0:
    return -1

  num = 1
  cnt = 1
  if k % 7 == 0:
    k = k//7

  for i in range(1000000):
    num = num % k
    if num == 0:
      return cnt
    else:
      num += pow(10, cnt, k)
      cnt += 1
  return -1

k = int(input())
print(main(k))

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

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    K = int(readline())
    if K%2==0:
        print(-1)
    else:
        seven = 7
        amari = set([7])
        ans = 1
        while True:
            seven = seven%K
            if seven==0:
                print(ans)
                break
            else:
                seven = seven*10+7
                if seven in amari:
                    print(-1)
                    break
                ans += 1
                amari.add(seven)


if __name__ == '__main__':
    main()

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

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

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

print(ans)

Solution (Python):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

k = ri()
a = k%10
if a in [1, 3, 7, 9]:
    s = 7
    cnt = 1
    while s%k:
        s = s*10 + 7
        s %= k
        cnt += 1
    print(cnt)
else:
    print(-1)

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

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

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

Solution (Python):
K = int(input())
c = 1
nana = 7
if K%2 == 0:
    print("-1")
else:
    n = 7%K
    while True:
        i = nana%K
        if i == 0:
            print(c)
            break
        elif c >= 10**6:
            print("-1")
            break
        else:
            nana = (10*i+n)%K
            c += 1

Solution (Python):

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

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

    d = {}
    for t in [1, 3, 7, 9]:
        d[t] = {}
        for i in range(10):
            d[t][t * i % 10] = i
    
    td = k % 10
    curr = 0
    count = 0
    while count == 0 or curr != 0:
        diff = 7 - (curr % 10)
        if diff != 0:
            if diff < 0:
                diff += 10
            coef = d[td][diff]
            curr += coef * k
        curr //= 10
        count += 1

    print(count)
    
submit()

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

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')






def solve():
    K = II()
    one = int(list(str(K))[-1])
    if one % 2 == 0 or one == 5:
        print(-1)
        return

    cnt = 1
    first_k = 7
    while 1:
        if first_k >= K:
            break
        first_k = first_k * 10 + 7
        cnt = cnt + 1
    

    q = first_k % K
    while 1:
        if q == 0:
            print(cnt)
            return
        q = (q * 10 + 7) % K
        cnt = cnt + 1


if __name__ == '__main__':
    solve()

Solution (Python):

def main():
    K = int(input())
    tmp = 7
    i = 0
    while i < 10**6:
        if tmp % K == 0:
            print(i+1)
            exit()
        else:
            tmp += 7 * pow(10,(i+1),K) % K
            tmp %= K
            i += 1 
    print(-1)

if __name__ == "__main__":
    main()

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

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

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

print(cnt)

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
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 print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False


def count_ones(n):

    
    
    
    count = 1;

    
    rem = 7

    if n == 7:
        return 1

    
    
    while rem != 0:
        
        
        
        rem = (rem * 10 + 7) % n
        count = count + 1

        if count > 10 ** 6:
            count = -1
            break

    
    
    return count

def main():
    K = I()
    MAX = 10 ** 6

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

    if K == 1:
        print(1)
        return

    print(count_ones(K))



if __name__ == '__main__':
    main()

Solution (Python):
import sys
from math import sqrt, gcd, ceil, log

from collections import defaultdict, Counter, deque

input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))



def f(n):
	i = 0
	while n%10 == 7:
		n //= 10
		i += 1
	return((n,i))
def f2(a, b):
	return(b + [0, 10][a > b] - a)
def main():
	n = int(input()); 
	dic = defaultdict(int)
	for i in range(1, 10):
		for j in (1, 3, 7, 9):
			dic[(j, (i*j)%10)] = i
	
	if n%10 in (1, 3, 7, 9):
		t = n%10; ans = 0
		m, ans = f(n*(dic[(t, n%10)]))
		
		while m != 0:
			
			m += n*dic[(t, f2(m%10, 7))]
			

			
			m, y = f(m)
			
			ans += y
		print(ans)



	else:print(-1)
	





if __name__ == "__main__":
	main()

Solution (Python):



import sys


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


def std_in():
    return sys.stdin.readline().strip()


def main():
    k = int(std_in())
    if k % 2 == 0:
        print(-1)
    elif k % 5 == 0:
        print(-1)
    else:
        i=0
        kk = k
        while 1:
            ks = str(kk)
            if ks.count("7") == len(ks):
                break
            one = kk % 10
            if one == 7:
                kk = kk // 10
                i += 1
            else:
                kk += k
        print(i + len(ks))


if __name__ == "__main__":
    main()

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

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

Solution (Python):
k = int(input())
if k % 2 == 0:
    print(-1)
elif k in [1,7]:
  	print(1)
else:
  amari = [7]
  tmp = 7
  for i in range(k):
      tmp = (tmp * 10) % k
      if tmp != 7:
          amari.append(tmp%k)
      else:
          break
  amari = amari * ((k//len(amari)) +1)

  ans = amari[0]
  for i in range(1, k+1):
      ans += amari[i]
      if ans % k == 0:
          print(i+1)
          break
  else:
    print(-1)

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

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

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

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

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

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

ans = -1
t = 7
amari = 7 % K
if K == 1 or K == 7:
    print(1)
    exit(0)
for i in range(1, 1000000):
    t = (t * 10) % K
    a = (t + amari) % K
    if a == 0:
        ans = i + 1
        print(ans)
        exit(0)
    else:
        amari = a
print(ans)

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

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

Solution (Python):
k = int(input())
c = 0
t = 7%k
a = [t]*(k+1)

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

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

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)




def isPrime(x):
  f = 2
  while f * f <= x:
    if x % f == 0:
      return False
    f += 1
  return True

def solve(k):
  x = 0
  maxVal =  k
  for i in range(maxVal):
    x += 7*pow(10,i,k)
    x %= k
    if x == 0:
      return i+1
  return -1



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

if __name__ == '__main__':
  main()

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

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

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

if i == k:
    print(-1)
else:
    print(i + 1)

Solution (Python):
import copy


def get_int():
    return int(input())


def get_string():
    return input()


def get_int_list():
    return [int(x) for x in input().split()]


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


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


def get_string_char_list():
    return list(str(input()))





'''
while (idx < n) and ():

    idx += 1
'''

def main():
    k = get_int()
    prev = 7 % k
    ret = -1

    amari = prev

    if amari == 0:
        ret = 1
    else:

        for i in range(1, k):
            prev = (prev * 10) % k
            amari = (amari + prev) % k

            if amari == 0:
                ret = i+1
                break

    print(ret)


def check(bunshi, k):
    return (bunshi % k == 0)


if __name__ == '__main__':
    main()

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

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

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

if k % 2 == 0 or k % 5 == 0:
    print("-1")
    
else:
    ans = len(str(k))
    s = int(str(7)* ans)
    while True:
        if s % k == 0:
            print(ans)
            break
        else:
            s = (s % k)*10 + 7
            ans += 1

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

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

Solution (Python):
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    k = kwargs["k"]
    res = 0
    p = 7
    rs = 0

    while True:
        res += 1
        r = p % k
        rs += r
        if rs % k == 0:
            break
        if r == 0 or res > 1000000:
            res = -1
            break
        p = r * 10


    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["k"] = [int(i) for i in cin][0]

    cout = main(kwargs)
    print(cout)

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


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

Solution (Python):
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    K = int(input())
    a = 7
    a %= K
    for k in range(K):
        if a % K == 0:
            print(k + 1)
            return
        a = a * 10 + 7
        a %= K
    print(-1)


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

K = input()
digit = len(K)
K = int(K)
divided = int(((10**(digit) - 1)*7) / 9)
flag = True
remains = np.zeros(K)
while flag:
  remain = divided%K
  if remain==0:
    flag = False
    print(digit)
  elif remains[remain-1]==1:
    flag = False
    print(-1)
  else:
    remains[remain-1] = 1
    digit += 1
    divided = remain*10 + 7

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

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

    repsept = 7 % K
    count = 1
    while repsept % K !=0:
        repsept = ((repsept * 10) + 7) % K
        count += 1
    return count

print(c_repsept())

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())
if K % 2 == 0:
    print(-1)
    exit()
if K % 5 == 0:
    print(-1)
    exit()

d = 7
cnt = 1
mo = d % K
while mo != 0:
    d *= 10
    d %= K
    mo = (mo + d)%K
    cnt += 1
print(cnt)

Solution (Python):
K = int(input())
if (K % 2 == 0 or K % 5 == 0):
    print(-1)
else:
    i = 0
    n = 7
    R = n % K
    while True:
      
        if (R == 0):
            print(i+1)
            exit()

        i += 1
        R = (((10 % K)*R)%K + 7%K) % K

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


k = int(input())
print(first_multiple(k))

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

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

def s(i, K):
    return 7*(pow(10, i+1, K) - 1)

flag = False
tmp = 9*K
for i in range(K+2):
    if s(i, tmp) % tmp == 0:
        flag = True
        print(i+1)
        break

if flag == False:
    print(-1)

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

Solution (Python):
import math

K = int(input())
ans = int(math.log10(K)) + 1
X = (10 ** ans - 1) // 9 * 7

while True:
  Y = X % K
  if Y==0:
    print(ans)
    break
  elif K%2==0 or K%5==0:
    print('-1')
    break
  else:
    X = Y * 10 + 7
    ans += 1

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

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

Solution (Python):

m=int(input())

kou = 1

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

    s=7%m
    k=7
    
    while 1:
        if s==0:
            print(kou)
            break
        
        
        k*=10
        k%=m
        s+=k
        s%=m
        
        kou+= 1

Solution (Python):
import sys

K = int(input())

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

print(-1)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

INF = 10**9+7

if __name__ == "__main__":
    k = int(input())
    if k%2 == 0:
        print(-1)
        sys.exit()
    cnt = 1
    a = 7
    d = [a]
    for i in range(10**6+1):
        if d[i]%k == 0:
            print(i+1)
            sys.exit()
        b = 10*d[i]
        b%=k
        b+=7
        b%=k
        d.append(b)
    print(-1)

Solution (Python):
k=int(input())
q=[7]
Q=[0]

for i in range(k) :
    q.append((q[i]*10)%k)
    if (q[i]+Q[i])%k==0 :
        print(i+1)
        exit()
    Q.append((q[i]+Q[i])%k)
    
else :
    print(-1)

Solution (Python):

def main():
    k = int(input())
    res = 1
    s = 7
    used = []
    if k % 2 == 0 or k % 5 == 0:
        return -1
    while True:
        s = s % k
        if s == 0:
            return res
        else:
            s = s*10+7
            res += 1

    
 
if __name__ == '__main__':
    print(main())

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

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

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
if k%7 == 0:
  k//=7
if is_prime(k):
  print(k-1)
  exit()
print(-1)

Solution (Python):
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    else:
        tmp = 7
        digits = 1
        while tmp % k != 0:
            tmp = (tmp * 10 + 7) % k
            digits += 1
        print(digits)


if __name__ == '__main__':
    main()

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

Solution (Python):
def main():
    K = int(input())
    Sum = 0
    Y = 7
    for i in range(K):
        Sum += Y
        Y = (Y*10)%K    
        if Sum % K == 0:
            print(i+1)
            return
    print(-1)
    return

main()

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

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

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

Solution (Python):
import sys
import math

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

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

    print(-1)


if __name__ == '__main__':
    main()

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

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

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

print(-1)

Solution (Python):


import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def isMultiple(s, m):
    tmp = 0
    for i in range(len(s)):
        tmp = (tmp * 10 + int(s[i])) % m
        if tmp == 0:
            return i
    return -1


k = int(readline())
acc = "7" * 50000000
if k % 2 == 0:
    ans = -1
else:

    ans = isMultiple(acc, k)
    if ans != -1:
        ans += 1

print(ans)

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

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

print(-1)

Solution (Python):
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    a = 1
    b = 0
    h = set()
    for i in range(10**6):
        a = a * 10 % k
        b = (a * 7 + b) % k
        if b == 0:
            print(i + 1)
            break
        if b in h:
            print(-1)
            break
        h.add(b)
    else:
        print(-1)


if __name__ == '__main__':
    main()

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

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

print(-1)

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

if k%2==0 or k%5==0:
    print('-1')
else:
    from itertools import accumulate
    ac = list(accumulate([7*pow(10, i, k)%k for i in range(999983)]))
    for idx, a in enumerate(ac):
        if a%k == 0:
            print(idx+1)
            break
    else:
        print('-1')

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

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

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

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

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

mod = [pow(10, i, k) for i in range(0, 1000000)]

num = 0
for i in range(0, 1000000):
    num += mod[i]
    if 7 * num % k == 0:
        print(i + 1)
        exit()

print('-1')

Solution (Python):
def power_func(a,n,p):
    bi = str(format(n,"b"))
    res = 1
    for i in range(len(bi)):
        res = (res*res) %p
        if bi[i] == "1":
            res = (res*a) %p
    return res



K = int(input())
seven=0

if str(K)[-1] in ['0','2','4','5','6','8']:
    print(-1)

else:
    i=0
    seven_mod=0
    while True:
        i+=1

        seven_mod = (seven_mod + 7%K * power_func(10,i,K))%K
        if seven_mod == 0:
            break

    print(i)

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

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

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

print(-1)