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

A = 7

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

print(-1)

Solution (Python):
k = int(input())
sevens = 7 % k

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

n = 7 % k
ans = -1
cnt = 1
checked = {n}
while n > 0:
    n = (n * 10 + 7) % k
    cnt += 1
    if n in checked:
        break
    checked.add(n)

if n == 0:
    print(cnt)
else:
    print(-1)

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


if K%2==0 or K%5==0:
    print(-1)
    sys.exit()
    
mod=7%K
if mod==0:
    print(1)
    sys.exit()
    
i=1
while True:
    mod=(10*mod+7)%K
    i+=1
    mod=mod%K

    if mod==0:
        print(i)
        break

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

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

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

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

Solution (Python):






k = int(input())

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

Solution (Python):
import sys

K = int(input())
a = []
i = 1

a.append(7 % K)
while i < K:
    a.append((a[i-1]*10+7) % K)
    i += 1

i = 0
while i < K:
    if(a[i]==0):
        print(i+1)
        exit(0)
    i += 1

print(-1)

Solution (Python):

def main():
    K = int(input())
    cnt = 1
    a = 7%K
    s = {a}
    for i in range(K):
        if a%K == 0:
            print(cnt)
            return
        a = a*10 + 7
        a = a % K
        if a in s:
            print(-1)
            return
        s.add(a)
        cnt += 1

if __name__ == "__main__":
    main()

Solution (Python):


k = int(input())
if k == 7 or k == 1:
    print(1)
    exit()

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

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

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

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

val = 7 % K

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

print(ans)

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

val = 7 % K

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

print(ans)

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

num = 7%K

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

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

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

x = 7
ans = 1



for i in range(3*n):
  if x%n==0:
    break
  ans+=1
  x= x*10 + 7
  x=x%n
    
if ans < 3*n:
  print(ans)
else:
  print(-1)

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

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

Solution (Python):
K = int(input())
 
sevens = 7 % K
count = 1
 
while(sevens % K !=0):
  
  sevens = sevens * (10 % K) + (7 % K)
  sevens = sevens % K
  
  count += 1
  if count > K:
    count = -1
    break
    
print(count)

Solution (Python):
K = int(input())
 
sevens = 7 % K
count = 1
 
while(sevens % K !=0):
  sevens = sevens * (10 % K) + (7 % K)
  sevens = sevens % K
  count += 1
  if count > K:
    count = -1
    break
    
print(count)

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

print(ans)

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

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

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

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

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

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

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

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

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

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

Solution (Python):
import math

k = int(input())
value = 7

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

if not isTrue:
    print(-1)

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

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

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

mod = 7
number = 1

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

if mod % K == 0:
    print(number)
else:
    print(-1)

Solution (Python):
K = int(input())
tmp = 1
ans = -1

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

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

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

ans = 1
num = 0
seven = 7

if not K%2:
    print(-1)
else:
    for i in range(K):
        num = num + seven
        seven = seven*10%K
        num = num%K
        if num == 0:
            print(ans)
            break
        ans += 1
    else:
        print(-1)

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

while a != 0:
  ans += 1
  a = (10*a + 7) % k
  
  if ans == 10**6:
    ans = -1
    break
print(ans)

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

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

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


if flag==0:
  print(-1)

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

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


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

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

        if cur == 0:
            print(i)
            return
    print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    K = int(input())
    a = [0] * (K + 1)
    a[1] = 7 % K
    for i in range(2, K + 1):
        a[i] = (a[i - 1] * 10 + 7) % K
    for i in range(1, K + 1):
        if a[i] == 0:
            print(i)
            return
    print(-1)


resolve()

Solution (Python):


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

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

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

elif K%7 == 0:
    x = -1
    b = 9*K/7
    c = 10%b

    for i in range(1,K+1):
        if c ==1:
            x = i
            break
        c = (c*10)%b

    print(x)

else:
    x = -1
    b = 9*K
    c = 10%b
    for i in range(1,K+1):
        if c ==1:
            x = i
            break
        c = (c*10)%b
        
    print(x)

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

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

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

Solution (Python):

k=int(input())

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

Solution (Python):

k=int(input())

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

Solution (Python):

k=int(input())

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

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array





sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K = ii()

    ret = []
    for i in range(K + 1):
        if i == 0:
            ret.append(7 % K)
        else:
            ret.append((ret[i - 1] * 10 + 7) % K)
    for i in range(K + 1):
        if ret[i] == 0:
            print(i + 1)
            exit()
    else:
        print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array





sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K = ii()

    ret = []
    for i in range(K + 1):
        if i == 0:
            ret.append(7 % K)
        else:
            ret.append((ret[i - 1] * 10 + 7) % K)
    for i in range(K + 1):
        if ret[i] == 0:
            print(i + 1)
            exit()
    else:
        print(-1)


if __name__ == '__main__':
    main()

Solution (Python):
def solve(string):
    n, k = 7, int(string)
    if k % 2 == 0 or k % 5 == 0:
        return "-1"
    for i in range(k):
        if not n % k:
            return str(i + 1)
        n = (10 * n + 7) % k


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    k = int(string)
    if k % 2 == 0 or k % 5 == 0:
        return "-1"
    n = 7
    for i in range(k):
        if not n % k:
            return str(i + 1)
        n = (10 * n + 7) % k


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
def solve(string):
    k = int(string)
    if k % 2 == 0 or k % 5 == 0:
        return "-1"
    n = 7
    ans = 1
    while n % k:
        n = (10 * n + 7) % k
        ans += 1
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

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

Solution (Python):
N = int(input())
def resolve():
  a = 7
  for i in range(1,N+1):
    if a % N == 0:
      return i
    a = (a * 10 + 7) % N
  return -1

ans = resolve()
print(ans)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

k = readInt()

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

print(-1)

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

Solution (Python):
import sys
import re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
    K=i_input()
    a = []
    
    a.append(7 % K)
    for i in range(1,K):
            a.append((a[i-1]*10+7)%K)
    
    for i in range(0,len(a),1):
        if(a[i] == 0):
            print(i+1)
            return

    print(-1)
    return
        
if __name__ == '__main__':
    main()

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

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

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

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

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

main()

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

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

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

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

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





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

j, ans = 0, -1
for j in range(K):
  if l[j] == 0:
    ans = j + 1
    break
    
print(ans)

Solution (Python):
K = int(input())
 
i, a = 0, 0
l = []
for i in range(K):
  a = (10*a + 7) % K
  l.append(a)

j, ans = 0, -1
for j in range(K):
  if l[j] == 0:
    ans = j + 1
    break
    
print(ans)

Solution (Python):
K = int(input())
 
i, a = 0, 0
l = []
for i in range(K):
  a = (10*a + 7) % K
  l.append(a)

j, ans = 0, -1
for j in range(K):
  if l[j] == 0:
    ans = j + 1
    break

print(ans)

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

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

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

i = 7 % K

result = set()
for x in range(K):
    if i == 0:
        print(x + 1)
        exit()
    if i in result:
        print(-1)
        exit()
    else:
        result.add(i)

    i = (i * 10 + 7) % K

print(-1)

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

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

Solution (Python):
k = int(input())
a = []
a.append(7 % k)

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

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

print(-1)

Solution (Python):

import sys


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

    for i in range(K):
        if A % K == 0:
            print(i+1)
            return

        A = (A * 10) + 7
        A %= K
    
    print(-1)


if __name__ == "__main__":
    main()

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

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

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

print(solve())

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

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

L = 9 * K

if L % 2 == 0 or L % 5 == 0:
    ans = -1
else:
    ans = 0
    R = 10
    while 1:
        ans += 1
        if R % L == 1:
            break
        else:
            R = (10 * R) % L

print(ans)

Solution (Python):


K=int(input())

mods=[0]*10**6

temp=7
ans=0
while mods[temp%K]==0 and mods[0]==0:
    mods[temp%K]=1
    ans+=1
    temp*=10
    temp+=7
    temp%=K

print(ans if mods[0]==1 else -1)

Solution (Python):
k = int(input())
a = [0 for _ in range(k)]
n = 7

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

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

Solution (Python):

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

Solution (Python):
k = int(input())
d1 = k % 10
mae = 0
sd = [0]*10
cnt = 0
if not d1 in (1, 3, 7, 9):
  print(-1)
  exit()
for i in range(1,10) :
  sd[d1 * i % 10] = i


for j in range(999999):
  d2 = 7 - mae % 10
  s = str(sd[d2] * k + mae)


  for i in range(len(s)-1, -1, -1):

    if (s[i]) == "7":
      cnt += 1
    else:
      s = s[0:i+1]
      mae = int(s)

      break

    if i == 0 :
      print(cnt)
      exit()

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

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

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

else:
    print(-1)

Solution (Python):



k = int(input())

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

Solution (Python):
import collections
import sys
import math
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
K=int(input())
if K%2==0 or K%5==0:
  print(-1)
ans=7%K
for i in range(K):
  if ans==0:
    print(i+1)
    exit()
  ans=((ans*10)+7)%K

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

if k%2==0 or k%5==0:
    print(-1)
else:
    while 1:
        n=(n*10+7)%k
        if n==0:
            break
        i+=1
    print(i)

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

Solution (Python):

k = int(input())

sevens = [0] * k

sevens[0] = 7 % k

if k == 7 or k == 1:
    print(1)
    
else:
    for i in range(1, k):
        new = (sevens[i - 1] * 10 + 7) % k
        sevens[i] = new

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

Solution (Python):
K = int(input())
def check(k):
    aaa = 0
    prev = 7%k
    for i in range(0,k):
        aaa+=1
        if prev == 0:
            return(aaa)
        prev = (prev*10+7)%k
    return(-1)
print(check(K))

Solution (Python):
k = int(input())
s = 7
num = 1
res = True
if k == 2:
    print(-1)
else:
    for i in range(k):
        s %= k
        if s == 0:
            res = False
            print(num)
            break
        num += 1
        s *= 10
        s += 7
    if res:
        print(-1)

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

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

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

cnt = 1

for i in range(k):
    if n % k == 0:
        break
    n = (n*10 + 7) % k
    cnt += 1

if n % k == 0:
    print(cnt)
else:
    print(-1)

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

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

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

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

Solution (Python):
k = int(input())
mod = 7 % k
counter = 1
memo = 1
mod_map = set()
mod_map.add(mod)
while mod != 0:
    mod = ((mod * 10) % k + 7) % k
    if mod not in mod_map:
        mod_map.add(mod)
    else:
        counter = -1
        break
    counter += 1
    if mod == 0:
        break
print(counter)

Solution (Python):
k = int(input())
mod = 7 % k
counter = 1
memo = 1
mod_map = set()
mod_map.add(mod)
while mod != 0:
    memo = ((memo % k) * (10 % k)) % k
    mod = (mod + 7 * memo) % k
    if mod not in mod_map:
        mod_map.add(mod)
    else:
        counter = -1
        break
    counter += 1
    if mod == 0:
        break
print(counter)

Solution (Python):
k = int(input())
mod = 7 % k
counter = 1
memo = 1
mod_map = set()
mod_map.add(mod)
while mod != 0:
    memo = ((memo % k) * (10 % k)) % k
    mod = (mod + 7 * memo) % k
    if mod not in mod_map:
        mod_map.add(mod)
    else:
        counter = -1
        break
    counter += 1
    if mod == 0:
        break
print(counter)

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

Solution (Python):
k = int(input())
x = 7%k
s = set()


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

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

first_mod = 7 % K
"""
cnt = 1
if first_mod == 0:
    print(1)
else:
    flg = True
    for i in range(2,K):
        seven = old * 10 + 7
        mod = seven % K
        cnt += 1
        old = seven
        if mod == 0:
            break
        if mod == first_mod:
            flg = False
            break
    if flg:
        print(cnt)
    else:
        print(-1)
"""
old_mod = now_mod = first_mod

cnt = 1
if first_mod == 0:
    print(1)
else:
    flg = False
    for i in range(2,K+1):
        now_mod = ((old_mod * 10) + 7) % K
        cnt += 1
        old_mod = now_mod
        if now_mod == 0:
            flg = True
            break
        if now_mod == first_mod:
            break
    if flg:
        print(cnt)
    else:
        print(-1)

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

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

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

t = 7
t %= k

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

Solution (Python):
K = int(input())
s = 7
flg = False
cnt = 0

for i in range(K+1):
    cnt += 1
    if s % K == 0:
        flg = True
        break
    s *= 10
    s %= K
    s += 7

if flg:
    print(cnt)
else:
    print(-1)

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

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

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

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

path = set()
a = 0
step = 0
while True:
    step += 1
    a = (a*10 + 7) % K
    if verbose: print (step, ':', a)
    if a == 0:
        print (step)
        break
    if a in path:
        print ('-1')
        break
    path.add(a)

Solution (Python):
k = int(input())
if k % 2 == 0:
    print(-1)
else:
    mod = 7 % k
    counter = 1
    memo = 1
    mod_map = set()
    mod_map.add(mod)
    while mod != 0:
        memo = ((memo % k) * (10 % k)) % k
        mod = (mod + 7 * memo) % k
        if mod not in mod_map:
            mod_map.add(mod)
        else:
            counter = -1
            break
        counter += 1
        if mod == 0:
            break
    print(counter)

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

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

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

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

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

  print(cnt)

Solution (Python):

import sys


def solve(K: int):
    lastMod = 0
    for i in range(K):
        lastMod = (lastMod*10+7)%K
        if lastMod == 0:
            print(i+1)
            return
    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())

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

else :
    print(-1)

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

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