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())
ans = 0
if K % 7== 0:
    K //= 7

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

Solution (Python):
def main():
  k = int(input())
  kint = 7 % k
  before = 7 % k
  if k == 1 or k == 7:
    print(1)
    exit()
  for i in range(k):
    x = (before * 10) % k
    before = x
    kint += x
    kint = kint % k
    if kint % k == 0:
      print(i + 2)
      exit()
  print(-1)
 
 
if __name__ == '__main__':
    main()

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

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

A = 7
ans = 1
while(A < K): 
    A = A*10 + 7
    ans += 1

while(True):
    
    A = A % K 
    if(ans > K):
        print("-1")
        exit()
    if(A==0): 
        print(ans)
        exit()
    A = A * 10 + 7 
    ans += 1

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

Solution (Python):
k = input()

if k[-1] in ['0','2','4','5','6','8']:
    print(-1)
else:
    k = int(k)
    i = 1
    x = 7
    while x != 0:
        if x % k == 0:
            break
        else:
            x = (x%k)*10 + 7
            i += 1
    print(i)

Solution (Python):
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import random

k=int(input())
A=[1]*(10**6+1)
A[0]=7%k
for i in range(1,10**6+1):
    A[i]=(A[i-1]*10)%k
ind=1
sum=A[0]
while(sum!=0 and ind<=10**6):
    if (A[ind]+sum)%k==0:
        ans=ind
        break
    sum=(sum+A[ind])%k
    ind+=1
if k==1 or k==7:
    print(1)
elif ind==10**6+1:
    print(-1)
else:
    print(ans+1)

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

Solution (Python):
n =int(input())
if n%2==0:
    print(-1)
elif n==1 or n==7:
    print(1)
else:
    ans =1
    start = 7
    while True:
        start = ((start%n*10%n)+7)%n
        
        
        if start ==0:
            ans+=1
            print(ans)
            break
        if ans>=1000000:
            print(-1)
            break
        ans+=1

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

ans = 1
X = 1
history = set()
while True:
    if X == 0:
        print(ans)
        exit()
    elif X in history:
        print(-1)
    else:
        ans += 1
        X = (X*10 + 1) % K

Solution (Python):

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





if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
K=int(input()) 

S=0
count=-1

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

print(count)

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


if K%2==0 or K%5==0:
    print(-1)
    exit()
elif K==7 or K==1:
    print(1)
else:
    M=7%K
    B=7%K
    for i in range(10**7):
        A=((B*10)%K)
        M+=A
        M%=K
        if M==0:
            print(i+2)
            exit()
        B=A+0

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


def get(k):
    ans=7
    i=1
    while True:
        if ans%k==0:
            return i
        ans=(ans*10+7)%k
        i+=1




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

else:
    print(get(k))

Solution (Python):


import sys
input=sys.stdin.readline

def main():
    K=int(input())
    rsum=0
    r=7
    for i in range(10**6+1):
        rsum=(rsum+r)%K
        r=(r*10)%K
        if rsum==0:
            print(i+1)
            exit()
    print(-1)
    
    
    
if __name__=="__main__":
    main()

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

result = 0
count = 0
tmp = K
m = tmp % 10

able = 0

for i in range(1, 10):
    if (m * i) % 10 == 7:
        tmp = K * i
        count += 1
        able = 1
        break

if able == 0:
    result = -1
    tmp = 0

while tmp > 7:
    able = 0
    tmp = tmp // 10
    n = tmp % 10
    for i in range(10):
        if (n + (m * i)) % 10 == 7:
            tmp += K * i
            count += 1
            able = 1
            break
    if able == 0:
        result = -1
        break
if result == -1:
    print(-1)
else:
    print(count)

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

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

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

def solve(K):
    f=0
    from collections import defaultdict
    if K==1:
        return 1
    elif K%2==0 or K%5==0:
        return -1
    
    if K%7==0:
        if K==7:
            return 1
        else:
            f=1
            K=K//7

    app = defaultdict(lambda: False)
    broken=False
    for n in range(1,K+1):
        if n==1:
            if f==1:
                amari = 1
            else:
                amari = 7%K
        else:
            if f==1:
                amari = (amari + pow(10,n-1,K) )%K
            else:
                amari = (amari + 7*pow(10,n-1,K) )%K
        
        if amari==0:
            broken=True
            break
        if app[amari]:
            broken=True
            break
        else:
            app[amari]=True
    if broken:
        return n
    else:
        return -1
    

print(solve(K))

Solution (Python):

import sys
from itertools import product
from itertools import combinations
from functools import reduce

def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

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

Solution (Python):





def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return x

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

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

def print_space(l):
    return print(" ".join([str(x) for x in l]))


import numpy as np




K = int(input())

if 7%K == 0:
    print(1)
    exit()


y = 7%K
x = 7%K

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

print(-1)

Solution (Python):
import sys
n = int(input())
if n % 2 == 0 or n % 5 == 0:
  print(-1)
  sys.exit()
p = 7
ans = 1
for i in range(1000000):
  q = p % n
  if q == 0:
    break
  else:
    p = 10 * q + 7
    ans += 1
if q != 0:
  print(-1)
else:
  print(ans)

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


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

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



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

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

ans = -1
mod = 0

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

print(ans)

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

print(-1)
exit()

Solution (Python):
n=input()
if n%7==0:
    n/=7
def numLen(K): 
      
    
    if(K % 2 == 0 or K % 5 == 0): 
        return -1
  
    number = 0
  
    len = 1
  
    for len in range (1, K + 1): 
          
        
        
        
        number = ( number * 10 + 1 ) % K 
      
        
        
        if number == 0: 
            return len
  
    return -1
  
print numLen(n)

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

k = int(input())

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

for i in range(10**6 + 1):
    r *= 10
    r %= k
    sum_r += r
    sum_r %= k
    if sum_r == 0:
        print(i + 2)
        sys.exit()
print(-1)

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

d=7%k

ans=1
nanawaruk=d
zyuwaruk=10%k

for i in range(10**6):
    if d==0:
        print(ans)
        exit()
    d=((nanawaruk*zyuwaruk)%k+d)%k
    zyuwaruk*=10
    zyuwaruk%=k
    ans+=1
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:
    if k%7==0:
        k//=7
    tmp=1
    cnt=1
    k*=9
    while (tmp*10-1)%k:
        tmp*=10
        tmp%=k
        cnt+=1
    print(cnt)

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

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






rem_list = []
first_rem = 7 % k
a = 7
cnt = 0
while True:
    r = a % k
    cnt += 1
    if r == 0:
        print( cnt )
        break
    elif cnt > 2 and cnt > k:
        print( -1 )
        break
    else:
        a = ( 10 * r + 7 ) % k

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





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

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

Solution (Python):
k = int(input())
cnt = 1
red = 7
memo = [0]*(10**6+10)
while cnt:
    red = red % k
    if red == 0:
        print(cnt)
        exit()
    if memo[red] == 1:
        print(-1)
        exit()
    memo[red] = 1
    red = red * 10 + 7
    cnt += 1

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

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

Solution (Python):
import time
start=time.time()
k=int(input())
if k%2==0:exit(print(-1))
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):
"""
AtCoder :: Beginner Contest 174 :: Repsept
https://atcoder.jp/contests/abc174/tasks/abc174_c
"""
import sys


def get_multiplier(d, p):
    for m in range(0, 10):
        if (d * m) % 10 == p:
            return m
    return - 1


def solve(K):
    soln = 0
    t = 0
    d = K % 10
    m = get_multiplier(d, 7)
    if m == -1:
        return -1
    t = t + (K * m)
    while t % 10 == 7:
        t //= 10
        soln += 1
    while(t):
        p = 7 - (t % 10)
        if p < 0:
            p = 17 - (t % 10)
        m = get_multiplier(d, p)
        if m == -1:
            return -1
        t += (m * K)
        while t % 10 == 7:
            t //= 10
            soln += 1
    return soln


def main():
    """Main program."""
    K = int(sys.stdin.readline())
    print(solve(K))


if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())
ans = [False for _ in range(K)]
num = 0
p = 7%K
for i in range(K+1):
    num += p
    p = (p*10)%K
    if ans[num%K] == False:
        ans[num%K] = True
    else:
        print("-1")
        break
    if num%K == 0:
        print(i+1)
        break

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

if k%7 == 0:
    k = k//7
k = k*9
ret = -1
if (k%2 == 0) or (k%5 ==0):
    print(-1)
else:
    for i in range(1,k+3):
        if pow(10,i,k) == 1:
            ret = i
            break
    print(ret)

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

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

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

solve()

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

Solution (Python):
from collections import defaultdict

K = int(input())

d = [0]*(K+1)

r = 0
ten = 1
while 1:
    r = (r+ten*7)%K
    ten *= 10
    ten %= K
    if r == 0:
        print(sum(d)+1)
        break
    if d[r] != 0:
        print(-1)
        break
    elif d[r] == 0:
        d[r] = 1

Solution (Python):
import sys
from io import StringIO
import unittest
import os


sys.setrecursionlimit(999999999)



def resolve(test_def_name=""):
    k = int(input())

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



class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """101"""
        output = """4"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """2"""
        output = """-1"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """999983"""
        output = """999982"""
        self.assertIO(test_input, output)

    
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

Solution (Python):









k = int(input())

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

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

for i in range(1,10**6+10):
    if n7<K:
        n7 = n7 * 10 + 7
        continue
    m = n7 % K
    if m == 0:
        print(i)
        exit()
    n7=m*10+7
print('-1')

Solution (Python):
def main(K):
    lst = [i for i in range(1, 10)]
    K_str = str(K)
    if K_str[-1] in ['0', '2', '4', '5', '6', '8']:
        print(-1)
    else:
        counta = 1
        a = 7
        amari_memo = 70 % K
        while a % K:
            counta += 1
            a = a % K + amari_memo
            amari_memo = amari_memo * 10 % K
        print(counta)


if __name__ == '__main__':
    K = int(input())
    main(K)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	k = int(input())
	
	
	if k % 2 == 0 or k%5 == 0:
		return -1
	amari = 0
	for i in range(mod*mod):
		amari += 7*pow(10, i, k)
		amari %= k
		if amari == 0:
			return i+1
			
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
import sys;K, = map(int, input().split())

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

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



seed = 0
OK = False
for i in range(K):
    seed = (10*seed +7)%K
    if seed == 0:
        print(i+1)
        OK = True
        break
if not OK:
    print(-1)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  

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

A = [1]
for i in range(K+2):
    A.append((A[-1]*10) % K)

a = 1
i = 1
while True:
    if a % K == 0:
        print(i)
        break
    else:
        a += A[i]
        a %= K
        i += 1

Solution (Python):
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print(-1)
  exit(0)
MOD = k
n = 0
l = []
root = 1
for i in range(1000000):
  n += 7 * root
  n %= k
  if n == 0:
    print(i + 1)
    exit(0)
  root *= 10
  root %= k
print(-1)

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())
a = defaultdict(int)
cnt = 0
N = 7
while True:
    cnt += 1
    s = N % K
    if s == 0:
        print(cnt)
        sys.exit()
    if s in a:
        print(-1)
        sys.exit()
    a[s] = 1
    N += pow(10,cnt,K)*7 
    N %= K

Solution (Python):

K = int(input())
judge=False
num = 7
for i in range(K):
    num = num % K
    
    if num == 0:
        print(i+1)
        judge = True
        break
    else:
        num = num*10+7
if judge == False:print("-1")

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

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

preamari = 7%K
ans = 1
while preamari != 0:
    preamari = (preamari*10 + 7%K)%K
    ans+=1

print(ans)

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

if K%2 == 0 or K%5 == 0:
    ans = -1
else:
    ans = 1
    mod = 7
    mod_bfr = 7

    while True:
        if mod % K == 0:
            break
        else:
            mod_nxt = mod_bfr * 10
            if mod_nxt < K:
                mod += mod_nxt
                mod_bfr = mod_nxt
            else:
                mod += mod_nxt % K
                mod_bfr = mod_nxt % K
            ans += 1

print(ans)

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

Solution (Python):
K = int(input())
f = 1
j = 7%K
while f < K and j != 0:
  j = (j*10 + 7)%K
  f += 1
if j == 0:
  print(f)
else:
  print('-1')

Solution (Python):

import sys

t  = [0,1,2,3,4,5,6,7,8,9]
tb = [0,7,0,9,0,0,0,1,0,3]

def solve(K: int):
    k =K
    temp = 0
    ct = 0
    b = k%10

    while(True):
        ct+=1
        u = temp%10
        p = -1
        for i in range(10):
            if (u + (b*i)) %10 == 7:
                p = i
                break
        if p == -1:
            print(-1)
            return
        temp += k*p
        if temp == 7:
            print(ct)
            return
        temp //= 10

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  
    solve(K)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



K = I()

d = defaultdict(int)
digit = 1
val = 7%K
while True:
    if val == 0:
        print(digit)
        exit()
    else:
        if d[val]:
            print(-1)
            exit()
        d[val] += 1
        digit += 1
        val = 10*val+7
        val %= K

Solution (Python):
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    K = ii()
    if K%2==0 or K%5==0:
        print(-1)
        return
    a = 7
    cnt = 1
    while a%K != 0:
        a = (10*a+7)%K
        cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    K = int(rl())
    
    mods = [7 % K]
    for _ in range(10 ** 6):
        if mods[-1] == 0:
            print(len(mods))
            return
        mods.append((mods[-1] * 10 + 7) % K)
    print(-1)


if __name__ == '__main__':
    solve()

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

tmp=7

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

print('-1')

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

Solution (Python):
K=int(input())
if K%2==0 or K%5==0:
    print(-1)
    exit()
if K==7 or K==1:
    print(1)
    exit()
if K==3:
    print(3)
s=7%K
for i in range(1000001):
    tmp=(10*(K-s))%K
    s=K-tmp+7
    
    if s==0 or s==K:
        print(i+2)
        exit()

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

Solution (Python):
K = int(input())
seven = 7
MOD7 = 7 % K
MOD70 = 70 % K
MOD77 = MOD7 + MOD70
if K % 2 == 0:
    print(-1)
elif MOD7 == 0:
    print(1)
else:
    for i in range(1,10**6):
        if MOD77 % K == 0:
            break
        MOD70 = (MOD70 * 10) % K
        MOD77 += MOD70
        MOD77 = MOD77 % K
    if i >= 10**6 - 1:
        print(-1)
    else:
        print(i+1)

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

mod_ans = 7%K
mod_10 = 10%K
mod_7_10 = 7%K
if 7%K == 0:
    print(1)
else:
    for i in range(int(K**(1/1))):
        mod_7_10 = (mod_7_10 * mod_10)%K
        mod_ans = (mod_ans + mod_7_10)%K

        if mod_ans == 0:
            print(i+2)
            break
    else:
        print(-1)

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

Solution (Python):
import sys
def main():
    k = int(input())
    
    if k == 7 or k == 1:
        print(1)
        sys.exit()
    
    r = 7%k
    g = {r}
    ans = 1
    while True:
        ans+=1
        r = (10*r+7)%k
        if r==0:
            print(ans)
            break
        if r in g:
            print(-1)
            break
        else:
            g.add(r)
main()

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(readline())

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

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

Solution (Python):




import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

k=I()
dpmod=[0 for i in range(10**6+100)]
dpmod[0]=7%k
for i in range(10**6+100-1):
    dpmod[i+1]=(10*dpmod[i])%k
dp=[0 for i in range(10**6+100)]
dp[0]=7%k
for i in range(10**6+100-1):
    if dp[i]%k==0:
        print(i+1)
        sys.exit()
    dp[i+1]=dp[i]+dpmod[i+1]
print(-1)

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

Solution (Python):
K = int(input())
n = "7"*(len(str(K))+1)
m = "7"*len(str(K))
p = int(n)
ans = 0
flag = 0
if(K%2==0):
  print("-1")
elif(K==1 or K==11 or K==111 or K==1111 or K==11111 or K==111111):
  print(len(str(K)))
elif(K==7 or K==77 or K==777 or K==7777 or K==77777 or K==777777):
  print(len(str(K)))
else: 
  while(ans <= K):
    ans += 1
    q = p % K
    p = str(q) + "7"
    p = int(p)
    if(q==0):
      print(ans+len(str(K)))
      flag = 1
      break
  if(flag==0):
    print("-1")

Solution (Python):
import sys
k=int(input())
d={}
ans=1
mod=7%k
mod1=7%k
d[mod1]=1
ch=0
  
while mod1!=0:
  mod=(mod*10)%k
  mod1=mod1+mod
  if mod1>=k:
    mod1=mod1%k
  if mod1 in d:
    ch+=1
    break
  if mod1 not in d:
    d[mod1]=1
  ans+=1
  
if ch==0:
  print(ans)
else:
  print(-1)

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

k = int(input())

n = 1

if k % 2  == 0:
    n = -1
else:
    r = 7 % k
    s = r

    while True:
        if r == 0:
            break
        elif n > 1000000:
            n = -1
            break
        else:
            r = (r * 10 + s) % k
            n += 1


print(n)

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

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

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0 and i<=100000000:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
if i>=100000000:
    i=-1
print(i)

Solution (Python):

k = int(input())
if k % 2 < 1 or k % 5 < 1:
    print(-1)
else:
    c = 1
    mod = 7 % k
    mop = 7 % k
    while mod > 0:
        mop = mop*10%k
        mod += mop
        mod %= k
        c += 1
    print(c)

Solution (Python):

import sys,math,numpy as np

from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()



def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(arr, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if arr[mid] == val:return mid
        elif arr[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,arr):
    for i in range(1,n):arr[i]+=arr[i-1]
    return arr;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;


def fun(k):
    current=7
    for i in range(1,10**6):
        if current%k==0:
            return i
        current*=10
        current+=7
        current=current%k
    return -1
k = ii1()
print(fun(k))

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