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

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

print(-1)

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

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

print(i)

Solution (Python):


import sys
input=sys.stdin.readline

def judge(k):
    if k%2==0 or k%5==0:
        print(-1)
    else:
        tmp=0
        for i in range(10**6):
            tmp+=7
            tmp%=k
            if tmp==0:
                print(i+1)
                break
            else:
                tmp*=10

k=int(input())
judge(k)

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

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

Solution (Python):

K = int(input())

now = 0
dic = {}

import sys
cnt = 1
while True:

    now = (now * 10 + 7) % K
    if now == 0:
        print (cnt)
        sys.exit()
    elif now in dic:
        print (-1)
        sys.exit()
    else:
        dic[now] = 1
    cnt += 1

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

cur = 7 % K
index = 1
for _ in range(2 * 10 ** 6):
    if cur == 0:
        break
    index += 1
    cur *= 10
    cur += 7
    cur %= K

if index > 10 ** 6 + 20:
    print(-1)
else:
    print(index)

Solution (Python):
def solve() :
    k = int(input())
    n = 1
    found = set()
    v = 7
    while v % k != 0: 
        if v in found :
            return -1
        found.add(v)
        v = ((v%k) * 10+7) % k
        n += 1
    return n


print(solve())

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

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


from bisect import bisect_left, bisect_right





input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    k = getN()
    al = {(7 % k): 1}
    mo = 7
    for i in range(k + 1):
        if mo % k == 0:
            print(i + 1)
            return
        mo = mo * 10 + 7
        mo %= k
        
        if mo in al:
            print(-1)
            return
        al[mo] = 1


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    
    solve()

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

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

Solution (Python):


K = int(input())

amari = set()
count = 1

r = 7%K

while r>0 and r not in amari:
  amari.add(r)
  r = (10*r+7)%K
  count += 1

if r==0:
  print(count)
else:
  print(-1)

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

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

Amari = [False] * K
cur = 7%K
ans = -1
for i in range(10**6 + 100):
    if cur == 0:
        ans = i+1
        break
    else:
        cur *= 10
        cur += 7
        cur %= K
print(ans)

Solution (Python):
d = int(input())
now = 0
for cnt in range(2*10**6):
  now *= 10
  now += 7
  now %= d
  if now == 0:
    print(cnt+1)
    break
else:
  print(-1)

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):
MOD = int(input())
ans = 0

tmp = 1
for i in range(100000000):
    ans = (ans + tmp * 7) % MOD
    if ans == 0:
        print(i + 1)
        break
    tmp *= 10
    tmp %= MOD
else:
    print(-1)

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    d = dict()
    k = ni()
    c = 7 % k
    x = d[c] = 1
    while True:
        c = (c * 10 + 7) % k
        if c in d:
            break
        x += 1
        d[c] = x
    print(d.get(0, -1))
    return

solve()

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

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

print(-1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

k=II()
seven=7%k
fin=set([seven])
for i in range(10**6):
    if seven==0:
        print(i+1)
        break
    seven=(seven*10+7)%k
    if seven in fin:
        print(-1)
        break
    fin.add(seven)

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

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

K = int(input())
i = 1
v = 7 % K
V = {v}
while v != 0:
	i += 1
	v = (10 * v + 7) % K
	if v in V:
		print(-1)
		break
	V.add(v)
else:
	print(i)

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

cnt=1
mod=7
while True:
    if mod % k  == 0:
        print(cnt)
        exit()
    cnt+=1
    mod*=10
    mod+=7
    mod%=k

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

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

print(main())

Solution (Python):


import sys
readline = sys.stdin.readline
read = sys.stdin.read

k, = [int(i) for i in read().split()]


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

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

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

print(digit)

Solution (Python):
k = int(input())
num = 7
count = 1
while count <= 10 ** 6:
    if num % k == 0:
        print(count)
        break
    else:
        num %= k
        num = num * 10 + 7
        count += 1
else:
    print(-1)

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

print(ans)

Solution (Python):
n = int(input())
A = [0] * n
i = 7%n
import sys
if i==0:
    print(1)
    sys.exit()

ans = 1
while A[i] == 0:
    A[i] = 1
    i = (i*10+7)%n
    ans += 1
    if i == 0:
        print(ans)
        sys.exit()

print(-1)

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

print(-1)

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

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque, defaultdict


from collections import Counter

from itertools import accumulate,combinations,permutations,product

from heapq import heapify,heappop,heappush

from functools import reduce,lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): 
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    

    K = int(input())
    
    
    
    

    cur=7%K
    cnt=1
    for _ in range(K+1):
        if cur==0:
            print(cnt)
            return
        cur*=10
        cur+=7
        cur%=K
        cnt+=1
    print(-1)




if __name__ == "__main__":
    main()

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

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


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

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

N = int(input())







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

Solution (Python):
k = int(input())
seen = [False]*k
now = 0
cnt = 0
while True:
    cnt += 1
    now = now*10+7
    now %= k
    if now == 0:
        break
    if seen[now]:
        print(-1)
        exit()
    seen[now] = True
print(cnt)

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

rem = 0
k = 0
while True:
    rem += (pow(10, k, K) * 7)
    rem %= K
    if rem == 0:
        print(k + 1)
        break
    k += 1
    if k == 1000001:
        print(-1)
        break

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

Solution (Python):
'''
自宅用PCでの解答
'''
import math

import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    k = int(ipt())
    al = [False]*k
    nk = 7
    for i in range(1,k+1):
        nk %= k
        if nk == 0:
            print(i)
            exit()
        else:
            if al[nk]:
                print(-1)
                exit()
            else:
                al[nk] = True
        nk = (nk*10+7)%k

    return None

if __name__ == '__main__':
    main()

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

print(ans)

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


if __name__ == "__main__":
    main()

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

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



k = int(sys.stdin.buffer.readline())

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

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

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