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

S = set()
cnt,n = 1,7
nothing = False

while True:
    if n % K == 0:
        print(cnt)
        break
    else:
        if n in S:
            print(-1)
            break
        else:
            S.add(n)
            n += (7 * pow(10,cnt,K))
            n %= K
            cnt += 1

Solution (Python):






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

    rest = [False]*K
    a = 7
    count = 1
    while a < K:
        a = 10*a+7
        count += 1
    r = a % K
    while r != 0:
        if rest[r-1]:
            print(-1)
            return
        else:
            rest[r-1] = True
            a = 10*r+7
            count += 1
            r = a % K
    print(count)
    
main()

Solution (Python):
import sys

input = sys.stdin.readline


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

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

    else:
        ans = -1

    print(ans)


if __name__ == "__main__":
    main()

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

if N%2 == 0 or N == 5:
    print(-1)
    quit()
    
temp = 7%N
ans = 1
while temp != 0:
    temp = (temp*10+7)%N
    ans += 1
    if ans >= 10**6+1000:
        print(-1)
        quit()
print(ans)

Solution (Python):
import math
K = int(input())
if K == 7 or K == 1:
  print(1)
elif math.gcd(K,10) != 1:
  print(-1)
else:
  if K % 7 == 0:
    K //= 7
  cnt = 1
  res = 10
  while True:
    cnt += 1
    res *= 10
    res %= (9 * K)
    if res == 1:
      break
  print(cnt)

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

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

dp = 7
ans = 1

while(ans <= 10000000):
    if dp % K == 0:
        print(ans)
        sys.exit()
    ans += 1
    dp = (dp * 10 + 7) % K

Solution (Python):
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
K=read()
mod=7%K
index=1
dic=defaultdict(int)
while(True):
    if mod==0:
        print(index)
        exit()
    if dic[mod]==1:
        print(-1)
        exit()
    dic[mod]=1
    mod=mod*10+7
    mod%=K
    index+=1

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

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

Solution (Python):
def main():
    k = int(input())
    tbl = {}
    v = int(0)
    cnt = 0
    while True:
        cnt += 1
        v = 10 * v + 7
        v = v % k

        if v == 0:
            print(cnt)
            break
        elif v in tbl.keys():
            print('-1')
            break
        else:
            tbl[v] = 0


if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())
A = 7 % K
X = 7 % K
n = 1
f = 0
while A != 0:
  X = (X * 10) % K
  A = (A + X) % K
  n += 1
  if n > K:
    print(-1)
    f = 1
    break
if f == 0:
  print(n)

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

Solution (Python):

import os
import sys
from io import BytesIO, IOBase

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


from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

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


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y


for _ in range(int(input()) if not True else 1):
    
    k = int(input())
    if k == 7:
        print(1)
        continue
    if k % 7 == 0:
        k = k // 7
    cur = 0
    start = 0
    found = False
    for i in range(8*10**6):
        start = (10*start + 1) % k
        if start == 0:
            found = i+1
            break
    print(-1 if not found else found)

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

X=[0]*K
m=0
p=7
for i in range(K):
  m=(m+p)%K
  if m==0:
    print(i+1)
    break
  elif X[m]==1:
    print(-1)
    break
  else:
    X[m]=1
  p=(p*10)%K

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

done = set()
i = 0
x = 7
flag = True
while x % K != 0 :
  if not x in done :
    done.add(x)
  else :
    flag = False
    break
  x = (x % K) * 10 + 7
  i += 1
    
if flag :
  print(i + 1)
else :
  print(-1)

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

Solution (Python):

k = int(input())

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

    r %= k
    if r == 0:
        break

if r != 0:
    print(-1)
else:
    print(c)

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

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

Solution (Python):
K=int(input())
nana=7
count=1
if K==7:
  print(1)
  exit()
if K==1:
  print(1)
  exit()
for i in range(5*10**6):
  count+=1
  nana=(nana*10+7)%K
  if nana==0:
    print(count)
    exit()

print(-1)

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

Solution (Python):
k=int(input())
mod=0
ans=0
for i in range(1000000):
    ans+=1
    mod=(mod*10+7)%k

    if mod==0:
        break
print(ans if ans!=1000000 else -1)

Solution (Python):
import sys


def _i(): return int(sys.stdin.readline().strip())


def main():
    n = _i()
    last = 7 % n
    if last == 0:
        return 1

    m = {last: True}
    cnt = 1
    while True:
        nxt = (10 * last + 7) % n
        cnt += 1

        if nxt == 0:
            return cnt

        if m.get(nxt, False):
            return -1

        m[nxt] = True
        last = nxt


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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())
    
    if K == 1:
        print(1)
        return
    elif K % 2 == 0:
        print(-1)
        return
        
    n = 7 % K
    seen = [False] * K
    for i in range(1, 10 ** 8):
        if n == 0:
            print(i)
            return
        elif seen[n]:
            print(-1)
            return
        else:
            seen[n] = True
            n = (n * 10 + 7) % K
            
    
    return


if __name__ == '__main__':
    main()

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

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

num,cnt="7",1
for i in range(1,n+1):
    if int(num)%n==0:
        print(i)
        exit()
    else:
        num +="7"
        num=str(int(num)%n)
print(-1)

Solution (Python):
def main():
    k = int(input())
    tmp = 7
    mul = 1
    p = 1
    while p < 10**7 and tmp % k != 0:
        mul *= 10
        tmp += 7 * mul
        mul %= k
        tmp %= k
        p += 1
    if tmp % k == 0:
        print(p)
    else:
        print(-1)

if __name__ == "__main__":
    main()

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

K=int(input().rstrip('\n'))
if K % 2 ==0:
  print(-1)
else:
  now = 7
  check = 0
  for i in range(1,K+1):
    if now % K ==0:
      print(i)
      check += 1
      break
    else:
      now = now%K
      now = now*10
      now += 7 
  if check ==0:
    print(-1)

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

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

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

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

print(-1)

Solution (Python):
k = int(input())
a = [0] * k

x = 0
i = 1
while True:
    x = x * 10 + 7
    x %= k
    m = x % k
    if m == 0:
        print(i)
        exit()
    if a[m] == 1:
        print(-1)
        exit()
    a[m] = 1
    i += 1

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

checked = [False for _ in range(k)]
r = 0
ans = -1

for i in range(1, k + 1):
    r = (r * 10 + 7) % k
    if checked[r]:
        break
    elif r == 0:
        ans = i
        break
    else:
        checked[r] = True

print(ans)

Solution (Python):
from itertools import count

K = int(input())
f = lambda x: (x*10+7)%K

a = 7%K
b = 7%K


for t in count(1):
    if a == 0:
        print(t)
        break
    if t > 1 and a == b:
        print(-1)
        break
    a = f(a)
    b = f(f(b))

Solution (Python):
K=int(input())
n=len(str(K))
N=int("7"*n)
if K%2==0 or K%5==0:
    print(-1)
else:
    while N%K!=0:
        n+=1
        N=N*10+7
        N%=K
    print(n)

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

Solution (Python):
K = int(input())
X = 1
temp = 7
ans = 1

if K == 7 or K == 1:
  print(ans)
  exit()

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

Solution (Python):
K=int(input())
t='7'
while int(t)<int(K):
  t+='7'
  
c=len(t)
t=int(t)
nums=[1]*K
while int(t)>0:
  t%=K
  if t==0:
    print(c)
    exit()
    
  if nums[t]==1:
    nums[t]=0
    t=10*t+7
    c+=1
  else:
    print(-1)
    exit()

Solution (Python):
K = int(input())
ans = 1
count = 1
m = 10
if K%7 == 0:
  K //= 7
for j in range(K):
  if count % K == 0:
    print(ans)
    exit()
  else:
    count = (count + m)%K
    m = m*10%K
    ans += 1
print(-1)

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

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

D=7
for i in range(1000000):
    if D%K==0:
        print(i+1)
        break

    D=D*10+7
    D%=K
else:
    print(-1)

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

dp = [0] * k

cur = 0
for i in range(k + 1):
    cur = (cur * 10 + 7) % k
    mod = cur % k
    if mod == 0:
        print(i + 1)
        break
    if dp[mod]:
        print(-1)
        break
    dp[mod] = 1

Solution (Python):
k=int(input())
i=1
a=7%k
m=10
v=set()
while True:
    v.add(a)
    if a==0:
        print(i)
        exit()
    a += m*7 %k
    a %= k
    if a in v:
        print(-1)
        exit()
    i+=1
    m *= 10
    m %= k

Solution (Python):
k=int(input())
if k%2==0:
    print (-1)
else:
    from collections import Counter
    c=Counter([])
    ans=1
    n=7%k
    flag=1
    while 1:
        if n==0:
            break
        if c[n]>=1:
            ans=-1
            break
        else:
            c[n]+=1
            n=(n*10+7)%k
            ans+=1
    print (ans)

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

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

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

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

    v = 7
    for i in range(1, 1000000):
        if v % K == 0:
            print(i)
            return

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

main()

Solution (Python):

import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys


buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(K):
    c = 0
    for i in range(1, 10**6+1):
        c *= 10
        c += 7
        c %= K
        if c == 0:
            return i
    return -1


def main():
    K = read_int()
    print(slv(K))


if __name__ == '__main__':
    main()

Solution (Python):
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

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

Solution (Python):
(K, ) = [int(n) for n in input().split()]

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

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

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

count = 1
flag = 0
current = 7
for i in range(2000000):
	if current%k == 0:
		flag = 1
		break

	current *= 10
	current += 7
	current %= k
	count += 1

if flag == 1:
	print(count)

else:
	print(-1)

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

ans = 1
x = 7
useds = [0] * (10**6+5)
useds[x] = 1
while True:
    if x%K == 0:
        print(ans)
        break
    x = (x*10 + 7) % K
    ans += 1
    if useds[x]:
        print(-1)
        break
    useds[x] = 1

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

history = {}
tmp = 0
for i in range(1, K + 2):
    tmp = (tmp * 10 + 7) % K
    key = str(tmp)
    if tmp == 0:
        ans = i
        break
    elif history.setdefault(key, False) == True:
        ans = -1
        break
    else:
        history[key] = True
        continue

print(ans)

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

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

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

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

Solution (Python):
k = int(input())
x, i = 0, 0
r = set()
while True:
    x = (x * 10 + 7) % k
    i += 1
    if x == 0:
        break
    if x in r:
        print(-1)
        quit()
    r.add(x)
print(i)

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7


def ddprint(x):
  if DBG:
    print(x)

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

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

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    
    K = read_int()
    seen = set()
    T = 7
    i = 1
    while T%K not in seen:
        if T%K == 0:
            return i
        seen.add(T%K)
        T = (T%K)*10+7
        i += 1
    return -1


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

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

def resolve():
    N,=pin()
    if N%2==0: 
        print(-1)
        return 
    cnt=7%N
    if cnt==0:
        print(1)
        return
    for i in range(2,10**7):
        cnt=cnt*10+7
        cnt%=N
        if cnt==0:
            print(i)
            return
    print(-1)

resolve()

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

Solution (Python):
class Modulo_Error(Exception):
    pass

class Modulo():
    def __init__(self,a,n):
        self.a=a%n
        self.n=n

    def __str__(self):
        return "{} (mod {})".format(self.a,self.n)

    
    def __pos__(self):
        return self

    def __neg__(self):
        return  Modulo(-self.a,self.n)

    
    def __eq__(self,other):
        if isinstance(other,Modulo):
            return (self.a==other.a) and (self.n==other.n)
        elif isinstance(other,int):
            return (self-other).a==0

    def __neq__(self,other):
        return not(self==other)
    
    
    def __add__(self,other):
        if isinstance(other,Modulo):
            if self.n!=other.n:
                raise Modulo_Error("異なる法同士の演算です.")
            return Modulo(self.a+other.a,self.n)
        elif isinstance(other,int):
            return Modulo(self.a+other,self.n)

    def __radd__(self,other):
        if isinstance(other,int):
            return Modulo(self.a+other,self.n)
        
    
    def __sub__(self,other):
        return self+(-other)

    def __rsub__(self,other):
        if isinstance(other,int):
            return -self+other
        
    
    def __mul__(self,other):
        if isinstance(other,Modulo):
            if self.n!=other.n:
                raise Modulo_Error("異なる法同士の演算です.")
            return Modulo(self.a*other.a,self.n)
        elif isinstance(other,int):
            return Modulo(self.a*other,self.n)
        
    def __rmul__(self,other):
        if isinstance(other,int):
            return Modulo(self.a*other,self.n)
        
    
    def Modulo_Inverse(self):
        x0, y0, x1, y1 = 1, 0, 0, 1
        a,b=self.a,self.n
        while b != 0:
            q, a, b = a // b, b, a % b
            x0, x1 = x1, x0 - q * x1
            y0, y1 = y1, y0 - q * y1

        if a!=1:
            raise Modulo_Error("{}の逆数が存在しません".format(self))
        else:
            return Modulo(x0,self.n)

    
    def __truediv__(self,other):
        return self*(other.Modulo_Inverse())
    
    def __rtruediv__(self,other):
        return other*(self.Modulo_Inverse())

    
    def __pow__(self,m):
        u=abs(m)

        r=Modulo(1,self.n)

        while u>0:
            if u%2==1:
                r*=self
            self*=self
            u=u>>1

        if m>=0:
            return r
        else:
            return r.Modulo_Inverse()

    
    def sqrt(self):
        if self==0:
            return self
        elif self.n==2:
            return self
        elif self.n%4==3:
            return self**((self.n+1)//4)
        else:
            p=self.n
            u=2
            s=1
            while (p-1)%(2*u)==0:
                u*=2
                s+=1

            z=Modulo(2,p)
            while z**((p-1)//2)!=-1:
                z+=1

            q=(p-1)//u
            m=s
            c=z**q
            t=self**q
            r=self**((q+1)//2)

            while m>1:
                k=1
                d=t*t

                while d!=1:
                    k+=1
                    d*=d
                    print(m,k)
                b=Modulo(2,p)**(2**(m-k-1))
                c,t,r,m=b*b,t*b*b,r*b,k
            return r


K=int(input())
X=-1
G=Modulo(1,K)
Z=Modulo(0,K)

for i in range(1,K+1):
    Z+=7*G
    G*=10

    if Z==0 and X==-1:
        X=i
print(X)

Solution (Python):
import sys, math

if(__name__ == "__main__"):
    """
    N, D = map(int, input().strip().split() )
    D_sq = D**2
    xy_list = []
    for i in range(N):
        xy = list( map(int, input().strip().split() ) )
        xy_list.append(xy)
    """
    K = int( input().strip() )

    Remainder = 7%K
    if(Remainder==0):
        print(1)
    else:
        Flag = True
        Times = 1
        for i in range(K):
            Remainder=(10*Remainder+7)%K
            Times += 1

            if(Remainder==0):
                print(Times )
                Flag = False
                break

        if(Flag==True):
            print(-1)

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

a = 7
flag = False

for i in range(1,K+1):
  b = a%K
  if b==0:
    flag = True
    break
  a = b*10 + 7
if flag:
  print(i)
else:
  print(-1)

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

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

Solution (Python):
k=int(input())
dp=[0]*1000001
val=0
cnt=0
flag=1
for i in range(0,1000000):
    cnt+=1;
    val=val*10+7
    if(val%k==0):
        break
    val=val%k
    if(dp[val]==1):
        flag=0;
        break;
    else:
        dp[val]=1
if flag==0:
    print(-1)
else:
    print(cnt)

Solution (Python):

from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import bisect
import math
import fractions
import sys
import copy


def L(): return sys.stdin.readline().split()


def I(): return int(sys.stdin.readline().rstrip())


def S(): return list(sys.stdin.readline().rstrip())


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def IR(n): return [I() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def LIR1(n): return [LI1() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def LR(n): return [L() for _ in range(n)]


alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007


def main():
    K = I()
    ans = 1
    tmp = 7

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

    while tmp % K != 0:
        tmp *= 10
        tmp += 7
        tmp %= K
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
def resolve():
    K = int(input())
    lst = [-1]*K
    st = 7
    count =1
    while True:
        st %= K
        if st ==0:
            print(count)
            return
        if lst[st]!=-1:
            print(-1)
            return
        lst[st]=1
        st = (st*10+7)%K
        count +=1
resolve()

Solution (Python):
K=int(input())
ans=-1
count=1
a=7
amari=[0]*K
while 1:
    b=a%K
    if b==0:
        ans=count
        break
    if amari[b]==1:
        break
    amari[b]=1
    count+=1
    a=10*b+7
print(ans)

Solution (Python):
K  = int ( input().strip() ) ;
v = 0 ;
r = -1 ;
for x in range (  1 ,  K + 1 ) :
	v = ( v * 10 + 7  ) % K ; 
	if v == 0 :
		r = x ;
		break ;
print ( r ) ;

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

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

amari = 0

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

print(-1)

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

K = int(input())
print(solve(K))

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  k=I()
  st=7
  if k==1 or k==7:
    return 1
  for i in range(1,1000001):
    st+=7*pow(10,i,k)
    st%=k
    if st==0:
      return i+1

  return -1


print(main())

Solution (Python):
n = int(input().rstrip())
passed = set()

from sys import exit
cnt = 1
tmp = 7
while 1:
    if tmp % n == 0:
        print(cnt)
        exit()
    elif tmp not in passed:
        passed.add(tmp)
        cnt += 1
        tmp = (tmp*10+7) % n
    else:
        print(-1)
        exit()

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left, bisect_right 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

K = int(input())

d = defaultdict(int)
dd = set()
num = 7
cnt = 1
if K == 7:
    print(1)
    exit()
while num % K != 0:
    num = num*10 + 7
    num %= K
    if num in dd:
        print(-1)
        exit()
    dd.add(num)
    cnt += 1
    
print(cnt)

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

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

def main():
    NI = lambda : int(sys.stdin.readline())

    K = NI()
    ans = 0
    m = 0
    while True:
        m = (m * 10 + 7) % K
        ans += 1
        if m == 0 or ans > K: break
    if ans <= K:
        print(ans)
    else:
        print(-1)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    for i in range(1, 10000001):
        cur *= 10
        cur += 7
        cur %= k
        if cur == 0:
            return print(i)

    print(-1)


if __name__ == '__main__':
    main()

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

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