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())
now = 1
ans = 7
mod = 10 ** 9 + 7
for i in range(K + 1):
    if ans % K == 0:
        print(now)
        exit()
    now += 1
    
    
    
    ans += 7 * pow(10, i + 1, K) % K


print('-1')

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

Solution (Python):
import sys

K = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors


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

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

print("-1")
sys.exit()

Solution (Python):
from collections import defaultdict

K=int(input())

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

memo=defaultdict(int)
tmp=0
ans=0
while True:    
    tmp=(tmp*10+7)%K
    ans+=1
    if tmp==0:
        print(ans)
        break
    elif memo[tmp]==1:
        print(-1)
        break
    else:
        memo[tmp]+=1

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

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    i = 1
    v = 7
    while True:
        if v % K == 0:
            print(i)
            break
        else:
            i += 1
            v = v * 10 + 7
            v %= 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())

mod_set = set()
num = 7
cnt = 1

while True:
    if num % k == 0:
        print(cnt)
        exit()
    else:
        if num % k in mod_set:
            print('-1')
            exit()
        else:
            mod_set.add(num % k)
    num = (num * 10 + 7) % k
    cnt += 1

Solution (Python):
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    k = int(input())
    tmp = 7
    cnt = 0
    if k%2 == 0 or k%5 == 0:
        print(-1)
        return

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



if __name__ == '__main__':
    main()

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

Solution (Python):

X = int(input())
L = len(str(X))



Y = 0

for l in range(L):
    Y += 7*10**l
    
flag = 0
for i in range(1000000):
    Y = Y%X
    

    if Y == 0:
        ans = L+i
        flag = 1
        break
    else: 
        Z = Y * 10 + 7
        if Z == Y:
            break
        else:
            Y = Z

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

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

D = 7%N

for i in range (1, N+1):
	if	D == 0:
		print(i)
		exit()
	else:
		D = (10*D+7)%N

print(-1)

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

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

Solution (Python):
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
k = int(input())




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

    m *= 10
    m += 7
    if m > k:
        m %= k

print(-1)

Solution (Python):
def main(k):
    r0 = 7 % k
    if r0 == 0:
        print(1)
        return
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    rs = [r0]
    while True:
        ri = (10 * rs[-1] + r0) % k
        if ri == 0:
            break
        rs.append(ri)
        if len(rs) >= 3 and rs[-1] == rs[-2] == rs[-3]:
            print(-1)
            return
    print(len(rs) + 1)


main(int(input()))

Solution (Python):


def main():
    import sys

    K = int( sys.stdin.readline() )

    A = 7
    add_digit = 7
    i = 1
    checked = set()


    while True:
        if A % K == 0:
            print(i)
            return

        elif A in checked:
            print("-1")
            return
        
        checked.add(A)
        add_digit = (add_digit * 10) % K
        
        next_A = add_digit + A
        next_A %= K

        A = next_A
        i += 1


if __name__ == "__main__":
    main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

k = INT()
l = len(str(k))
if k % 2 == 0:
    print(-1)
    exit()
dp = [-1 for _ in range(10 ** 6 + 100)]
for i in range(10 ** 6 + 100):
    if l > i + 1:
        continue
    elif l == i + 1:
        num = 0
        for _ in range(i):
            num *= 10
            num += 7
        if k > num:
            continue
    if dp[i - 1] == -1:
        num = 0
        for _ in range(i):
            num *= 10
            num += 7
        dp[i] = num % k
    else:
        dp[i] = (dp[i - 1] * 10 + 7) % k
    if dp[i] == 0:
        print(i)
        exit()
print(-1)

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

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

Solution (Python):
K,=list(map(int, input().split()))
se = 7
fiv = 1
for i in range(1,1000000):
  if K <= se:
    st = i
    break
  fiv *= 10 
  se = se + 7 * fiv
q1 = 7 * fiv % K
q2 = se % K
if q2 == 0:
  print(st)
  exit()
for i in range(st,1000000):
  if q2!=0:
    q1 = (10*q1) % K 
    q2 = (q1+q2)%K
    continue
  print(i)
  exit()  
print("-1")

Solution (Python):


k = int(input())

now = 1

if(k%2==0)or(k%5==0):
    print("-1")
else:
    past = 0
    for i in range(1,k+1):
        past = (past * 10 + 7) % k
        if past == 0:
            print("{}".format(i))
            break

Solution (Python):

import sys


def solve(K: int):
    if K % 2 == 0:
        print(-1)
    else:
        num = 7
        cnt = 1
        stop = 10 ** 7
        while cnt < stop:
            if num % K == 0:
                print(cnt)
                return
            else:
                num *= 10
                num += 7
                num %= K
                cnt += 1
        print(-1)
    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())
r=7%k
if r==0:
    print(1)
else:
    for i in range(k):
        r=(r*10+7)%k
        if r==0:
            print(i+2)
            break
    if i == k-1:
        print(-1)

Solution (Python):
K = int(input())
rest = 7%K
count=1
while (count<=K):
    if rest == 0:
        print(count)
        exit()
    count +=1
    rest = (rest%K*10%K + 7%K)%K
print(-1)

Solution (Python):
k = int(input())
f = 7
r = f % k
r_10 = 10 % k
r_7 = 7 % k
n = pow(10, 6)
ans = False
if k % 2 == 0:
    print(-1)
else:
    for i in range(1, n+1):
        if r % k == 0:
            ans = True
            break
        r = (r*r_10 + r_7) % k

    if ans:
        print(i)
    else:
        print(-1)

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

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

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

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

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

Solution (Python):
from sys import stdin
from sys import setrecursionlimit
import bisect   
setrecursionlimit(10 ** 7)

k = int(input())
now = 7

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

print(-1)

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

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

Solution (Python):
def junkan(x):
    if x == 1:
        return 1
    one = 1
    one *= 10
    for cnt in range(1000001):
        d, m = divmod(one, x)
        if m == 1:
            break
        elif d == 0:
            one *= 10
        else:
            one = m
            one *= 10
        
    return cnt+1

if __name__ == "__main__":
    K = int(input())
    flag = True

    if K%2 == 0 or K%5 == 0:
        flag = False
        print(-1)
    elif K%7 == 0:
        K = K//7
    K = K*9
        
    if flag:
        print(junkan(K))

Solution (Python):
time = 1
K = int(input())
sev = 7
while True:
    if K % 2 == 0 or time > K:
        print(-1)
        break
    elif sev % K == 0:
        print(time)
        break
    else:
        sev = sev % K * 10 + 7
        time += 1

Solution (Python):
import sys

def main():
    K = int(sys.stdin.readline().rstrip())

    A = [True] * K

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

main()

Solution (Python):
import os
import sys
from io import BytesIO, IOBase











          



          




              







def main():
    k = int(input())
    if k%2 == 0:
        print(-1)
    else:
        pass
    
        rem = 7%k

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

            rem = 10*rem + 7
            rem %= k

        print(ans)

        


        





































BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

 
if __name__ == "__main__":
    main()

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

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

    NOW=0

    for i in range(1,10**6+3):
        NOW=NOW+7*pow(10,i,K)
        NOW%=K

        if NOW==0:
            print(i)
            break
    else:
        print(-1)

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

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

    NOW=0

    for i in range(1,10**6+3):
        NOW=NOW+7*pow(10,i,K)
        NOW%=K

        if NOW==0:
            print(i)
            break
    else:
        print(-1)

Solution (Python):
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))


K = int(input())
def main():
    k = 7
    count = 1
    re = 1
    if K % 2==0:
        print(-1)
        return
    while True:
        if k % K == 0:
            print(count)
            return
        re =  (re*10)%K
        k = (k+7*re)%K
        count += 1
        if count >= 10**7:
            print(-1)
            return


main()

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

    ans = 0
    ketasave = 0
    ng = False
    while True:
        for _ in range(9):
            ans += k
            if ans % 10 == 7:
                while ans % 10 == 7:
                    ans -= 7
                    ans //= 10
                    ketasave += 1
                break
        else:
            ng = True
            break

        if ans==0:
            break
            
    print(ketasave if not ng else -1)

main()

Solution (Python):
import sys

k = int(input())

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

rest = [7 % k]


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

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

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

Solution (Python):

K = input()
k = int(K)





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

    
    if r == 0:
        print(i)
        exit()
    
print(-1)

Solution (Python):
def solve():
  K = int(input())
  if K%2==0 or K%5==0:
    return -1
  ans = 1
  cnt = 7%K
  i = 1
  while cnt!=0:
    cnt += 7*pow(10,i,K)
    cnt %= K
    i += 1
    ans += 1
  return ans
print(solve())

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

s = set()
x, ans = 7 % k, 1
while True:
    if x == 0:
        break

    if x in s:
        ans = -1
        break

    s.add(x)
    x = (x*10+7) % k
    ans += 1

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


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

from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  
from functools import reduce
from math import gcd


def lcm(a, b):
    
    g = gcd(a, b)
    return a // g * b


K = int(input())
modks = [7 % K]
for i in range(1, 10**6 + 100):
    modks.append((modks[-1] + 7 * pow(10, i, K)) % K)


for i, m in enumerate(modks, start=1):
    if m == 0:
        exit(i)
print(-1)

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

Solution (Python):

import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

k = readint()
flag = 1
if k%2==0 or k%5==0:
    flag = 0

if flag:
    a = 7
    a %= k
    i = 1
    while 1:
        if a%k==0:
            print(i)
            exit()
        else:
            a+=7*pow(10,i,k)
            a%=k
            i+=1
else:
    print(-1)

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

s = 0
c = 1

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

if c > i+1:
    print('-1')
else:
    print(c)

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

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

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

Solution (Python):
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()


k = inp()
if k % 2 == 0:
    print(-1)
    sys.exit()
if k % 7 == 0:
    k //= 7
n = 1
cnt = 1
for i in range(1001001):
    n = n % k
    if n == 0:
        print(cnt) 
        sys.exit()
    cnt += 1
    n *= 10
    n += 1 
print(-1)


end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

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

Solution (Python):
def main():
    K = int(input())
    if K % 2 == 0 and K % 5 == 0:
        print(-1)
        exit()
    ans = 0
    ten = 1
    mod = [0] * (10**6+5)
    for i in range(10**6):
        tmp = 7 * ten
        tmp %= K
        mod[i] = tmp
        ten *= 10
        ten %= K

    pre = 0   
    for i in range(10**6):
        pre += mod[i]
        if pre % K == 0:
            print(i+1)
            exit()

    print(-1)


if __name__ == "__main__":
    main()

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

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

ans = 0
x = 7
T = True
while T:
  ans += 1
  
  if x % K == 0:
    print(ans)
    quit()
  x = x * 10 + 7
  x %= mod

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




def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
	k=II()
	a=0

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

	print(-1)





if __name__ == "__main__":
	main()

Solution (Python):
import sys

K = int(input())

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

if K % 7 == 0:
    K //= 7

count = 0
candidate = 1

while True:
    count += 1
    rem = candidate % K
    if rem == 0:
        print(count)
        sys.exit(0)
    candidate = 10*rem + 1

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')


def solve():
    k = II()
    ans = 0
    for i in range(k + 1):
        ans += 7 * pow(10, i, k)
        ans %= k
        if ans:
            continue
        else:
            print(i + 1)
            return
    print(-1)
    return



if __name__ == '__main__':
    solve()

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

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

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

K = int(input())
amari = []
s = 0
before = 0
for i in range(10 ** 6 + 1):
    if i == 0:
        s += 7 % K
        before = 7 % K
    else:
        before = before * 10 % K
        s += before
    s = s % K
    if s == 0:
        break
else:
    print("-1")
    sys.exit()

print(i + 1)






"""
7
77
777
7777

7
70 == 7 * 10 =
700 ==  



1
11
111
1111

k = 3
1 == 1
10 == 1
100 == 1

k = 4
1 == 1
10 == 2
100 == 0
100 == 10 * 10 == 2 * 10
"""

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

if k % 2 == 0:
	print(-1)
elif k % 5 == 0:
	print(-1)
else:
	val = 0
	keta = 7
	while True:
		if cnt == 0:
			keta = 7
		else:
			keta = (keta * 10) % k
		val = (val + keta) % k
		
		if val % k == 0:
			break
		else:
			cnt += 1
	print(cnt + 1)

Solution (Python):
from collections import Counter
def main():
    K = int(input())
    S = [7] * K
    T = [0] * len(S)

    if K == 7 or K == 1:
        print(1)
        return
    
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return
    
    P = K
    T[0] = S[0] % P
    power = 1

    ans = -1
    for i in range(1, len(S)):
        power *= 10
        power %= P
        T[i] = T[i-1] + power * S[i]
        T[i] %= P

        if T[i] == 0:
            ans = i + 1
            break

    
    
    
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import math
import sys

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

    if K%2==0:
        print(-1)
        sys.exit()
    elif K%5==0:
        print(-1)
        sys.exit()
    n=0
    a=7
    while True:
        if a%K==0:
            break
        n+=1
        a=(a+(pow(10,n,K)*7))%K
    print(n+1)

if __name__=="__main__":
    main()

Solution (Python):
import math
K = int(input())
if math.gcd(10, K) != 1:
    print(-1)
else:
    for i in range(1, 10**6+1):
        if 7*(pow(10, i, 9*K)-1) % (9*K) == 0:
            print(i)
            break

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

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

if k % 2 ==0 or k % 5 == 0:
    print(-1)
else:
    ans = 1
    tempmod = 0
    while True:
        tempmod = (tempmod + 7*pow(10, ans-1, k)) % k
        if tempmod == 0:
            print(ans)
            exit()
        else:
            ans = ans + 1

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

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

Solution (Python):

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

Solution (Python):
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
k=N()
x=7%k
ans=1
for i in range(2*k):
    if x==0:
        print(ans)
        break
    x=x*10+7
    x%=k
    ans+=1
else:
    print(-1)

Solution (Python):
k=int(input())
flag=1
ans=1
r=7%k
p=r
if k%2==0:
    print(-1)
    exit()
if k%5==0:
    print(-1)
    exit()
while flag!=0:
    if r%k==0:
        flag=0
    else:
        ans+=1
        p=(p*10)%k
        r+=p
print(ans)

Solution (Python):
K = int(input())
mod = 7 % K
if mod == 0:
    print(1)
    quit()

s = set()
s.add(mod)
ans = 1
while mod != 0:
    mod = (mod*10 + 7) % K
    ans += 1
    if mod in s:
        print(-1)
        quit()
    s.add(mod)

print(ans)

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

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

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

Solution (Python):
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter

from functools import lru_cache

sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


x = 7
ans = 1
k = inp()
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
while True:
    if x % k == 0:
        print(ans)
        exit()
    else:
        x += 7 * pow(10, ans, k) % k
        ans += 1

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

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

print(f(K))

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

s=7
cnt=1
m=0

while(1):

  t=s%k
  if m==0 and t!=s:
    m=t
  elif m==t:
    print("-1")
    break

  if t==0:
    print(cnt)
    break
  else:
    s=t*10 + 7

  cnt+=1

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

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    K=ii()

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

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


    
    
    
    
    
    
    
    
    
    
            
    
    
    
                
    


if __name__ == "__main__":
    main()

Solution (Python):
import sys

K = int(input())
base = 0
seen = set()

for i in range(10**6):
    base += 7 * pow(10, i, K)
    base %= K
    if base == 0:
        print(i+1)
        sys.exit()
    elif base in seen:
        print(-1)
        sys.exit()
    seen.add(base)

Solution (Python):
k = int(input())
p = -1
if((k%2)*(k%5) != 0):
    p = 1
    a = 7%k
    while(a > 0):
        a *= 10
        a += 7
        a %= k
        p += 1
print(p)

Solution (Python):
def main():
    k = int(input())
    
    t = 0
    for i in range(10**6):
        t += (7*pow(10,i,k))
        t %= k
        if t==0:
            print(i+1)
            return

    print(-1)    

if __name__ == "__main__":
    main()

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

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

print(-1)

Solution (Python):
import sys


def resolve(in_):
    k = int(next(in_))
    if not k % 2:
        return -1

    seven = 7 % k

    for i in range(1, 1000000):
        if not seven:
            return i
        i += 1
        seven = seven * 10 + 7
        if seven >= k:
            seven %= k

    return -1

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

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

Solution (Python):

n=int(input())
f=0
ans=7
if n%2==0:
    print(-1)
else:
    count=1
    while(ans<n):
        ans*=10
        ans+=7
        count+=1
    for i in range(count,10**6+1):
        ans=ans%n
        if ans==0:
            print(i)
            f=1
            break
        ans*=10
        ans+=7
    if f==0:
        print(-1)

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

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

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


now, cnt = 7, 1
while now % K != 0:
    cnt += 1
    now = now * 10 % K + 7

print(cnt)

Solution (Python):
k=int(input())
n='7'
cnt=1
if k%2==0 or k%5==0:
  print(-1)
  exit()
while True:
  if int(n)%k!=0:
    n=int(n)%k
    n=str(n)+'7'
    cnt+=1
  else:
    print(cnt)
    exit()