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):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

INF = float("inf")


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

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

Solution (Python):
K = int(input())
MAX = pow(10,6)+10

now = 0
SET = set([])
for i in range(MAX):
  now = (now*10+7)%K
  if now == 0:
    print(i+1)
    exit()
  else:
    if now in SET:
      print(-1)
      exit()
    else:
      SET.add(now)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
 
def main():
    k=int(input())
    ans=1
    amari=0
    for _ in range(10**6+5):
        amari = (amari*10+7)%k
        if amari==0:
            print(ans)
            break
        ans+=1
    else:
        print(-1)

 
if __name__=='__main__':
    main()

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

if K==1:
    print(1)
    exit()
if K==7:
    print(1)
    exit()
ans=1
MOD=set()

cur=7
while True:
    if cur==0:
        print(ans)
        exit()
    else:
        r=cur%K
        if r in MOD:
            print(-1)
            exit()
        else:
            MOD.add(r)
        cur=(cur*10+7)%K
        ans+=1

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

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
from math import gcd
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

Solution (Python):
k = int(input())
i = 1
x = 7 % k
seen = {x}
while x != 0:
	x = (10 * x + 7) % k
	i += 1
	if x in seen:
		print(-1)
		break
	seen.add(x)
else:
	print(i)

Solution (Python):
K = int(input())
c = 7
i = 1
p = c%K
while i<=K:
  if p==0:
    print(i)
    break
  else:
    p = (p*10+7)%K
    i += 1
else:
  print(-1)

Solution (Python):
k=int(input())
ans=0
dev=7
while dev%k and ans <=k+3:
    ans+=1
    dev+=7*pow(10,ans,k)
    dev%=k
if ans==k+4:print(-1)
else:print(ans+1)

Solution (Python):


'''
Author: andyli
Time: 2020-08-02 19:55:49
'''

import os
from io import BytesIO, IOBase
import sys


def main():
    n = int(input())
    t = 0
    for i in range(1,n+1):
        t = (t*10 + 7) % n
        if not t:
            print(i)
            return
    print(-1)
    return



BUFSIZE = 1048576


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)
def input(): return sys.stdin.readline().rstrip('\r\n')




if __name__ == '__main__':
    main()

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

Solution (Python):
def main():
    K = int(input())
    if K % 2 == 0:
        print(-1)
        exit()

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


if __name__ == "__main__":
    main()

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

k = I()
tmp = 0
for i in range(k+1):
    tmp += 7 * pow(10, i, k)
    tmp %= k
    if tmp % k == 0:
        print(i+1)
        quit()
print(-1)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve(K):
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return
    X = 7
    cnt = 1
    while True:
        if X % K == 0:
            print(cnt)
            return
        cnt += 1
        X = X * 10 + 7
        X %= K


def main():
    
    
    K = Scanner.int()
    solve(K)


if __name__ == "__main__":
    main()

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

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

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

INF = 10**8

w = 0
for i in range(INF):
  w += 7 * pow(10,i,K)
  w %= K
  if w == 0:
    print(i+1)
    break
  else:
    if w in hist:
      print(-1)
      break
    else:
      hist.add(w)

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

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

Solution (Python):
def solve(k):
    x = 7
    checked = set()
    ans = 1
    while True:
        x %= k
        if x == 0:
            return ans
        if x in checked:
            return -1
        checked.add(x)
        x = x * 10 + 7
        ans += 1


k = int(input())
print(solve(k))

Solution (Python):
"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


import sys
from functools import lru_cache, cmp_to_key
from collections import defaultdict as dd, deque, Counter as C
from bisect import bisect_left as bl, bisect_right as br, bisect
from math import sqrt
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var, end="\n"): sys.stdout.write(str(var)+end)
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n = int(data())
if n % 2 == 0 or n % 5 == 0:
    print(-1)
f = 7
cnt = 1
while cnt <= 2 * 10 ** 6:
    if f % n == 0:
        out(cnt)
        break
    cnt += 1
    f = f * 10 + 7
    f %= n

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

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

Solution (Python):
k = input()
v = 7 % k
l = 1

for _ in xrange(k+10):
    if v != 0:
        v = (v * 10 + 7) % k
        l += 1
    else:
        break

if v == 0:
    print l
else:
    print -1

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

Solution (Python):
k = int(input())
m = [False] * k
s = 0
d = 7 % k
i = 0
while True:
  s = (s + d) % k
  d = d * 10 % k
  i += 1
  if s == 0:
    print(i)
    break
  if m[s]:
    print(-1)
    break
  m[s] = True

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

ans = -1
cur = 7
r = 0

for i in range(K):
    r += cur % K
    r %= K
    if r == 0:
        ans = i + 1
        break
    cur *= 10
    cur %= K

print(ans)

Solution (Python):
import sys

K = int(input())
if K%7==0:
    K = K//7

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

Solution (Python):

K = int(input())

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

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

print(-1)

Solution (Python):
from collections import defaultdict

k = int(input())

ms = defaultdict(int)

ans = 1
i = 7
while True:
    if i % k == 0:
        print(ans)
        exit()
    i = (i * 10 + 7) % k
    if ms[i] > 0:
        print(-1)
        exit()
    ms[i] += 1
    ans += 1

Solution (Python):
import sys


def input():
    return sys.stdin.readline().rstrip()


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

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

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



if __name__ == "__main__":
    main()

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

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

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

A = [0 for _ in range(K)]

a = 0
i = 1
while True:
  a *= 10
  a += 7
  a %= K
  if A[a] > 0: 
    print(-1)
    sys.exit()
  if a == 0:
    print(i)
    sys.exit()
  A[a] = i
  i += 1

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

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


if __name__ == '__main__':
    solve()

Solution (Python):
def main():
    n = int(input())
    mod = 0
    pow10 = 1
    for i in range(20*n):
        mod = (mod+7*pow10) % n
        if mod == 0:
            print(i+1)
            return
        pow10 = pow10*10 % n
    print(-1)


main()

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

Solution (Python):
k = int(input())
x = 7
ans = 1
s = set()
while x%k != 0:
    ans += 1
    x = (x*10%k+7)%k
    if x in s:
        ans = -1
        break
    s.add(x)
print(ans)

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

X = 0

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

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    K = NI()
    tmp = 7
    for i in range(1000005):

        if tmp % K == 0:
            print(i+1)
            exit()
        tmp = tmp * 10 + 7
        tmp = tmp % K
    print(-1)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    K = int( input())
    now = 7
    now %= K
    for i in range(10**7):
        if now == 0:
            print(i+1)
            return
        now = (now*10+7)%K
    print("-1")
if __name__ == '__main__':
    main()

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

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(K):
    visited = [False] * K
    p = 7 % K
    for i in range(K):
        if p == 0:
            return i + 1
        if visited[p]:
            return - 1
        visited[p] = True
        p = (p * 10 + 7) % K


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



T1 = """
101
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
4
"""
T2 = """
2
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
-1
"""
T3 = """
999983
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
999982
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()

Solution (Python):
def examA():
    X = I()
    if X<30:
        ans = "No"
    else:
        ans = "Yes"
    print(ans)
    return

def examB():
    N, D = LI()
    cnt = 0
    for _ in range(N):
        x, y = LI()
        if x**2+y**2<=D**2:
            cnt += 1
    ans = cnt
    print(ans)
    return

def examC():
    N = 10**7
    K = I()
    cur = 0
    now = 1
    ans = -1
    for i in range(N):
        cur += 7 * now
        cur %= K
        if cur==0:
            ans = i+1
            break
        now *= 10
        now %= K
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep,alphabet_convert
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    k = int(input())
    if k%2==0 or k%5==0:
        print(-1)
        exit()
    
    x = 7
    ans = 1
    while x % k != 0:
        x = (x*10 + 7) % k
        ans += 1
    print(ans)
main()

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
k=int(input())
cur=0
for i in range(10**6+1):
  cur=(cur+7*pow(10,i,k))%k
  if cur==0:
    print(i+1)
    break
else:
  print(-1)

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

r = set()
x = 7
i = 1
while True:
    rr = x % k
    if rr == 0:
        print(i)
        break
    if rr in r:
        print(-1)
        break
    x = (x * 10 + 7) % k
    i += 1
    r.add(rr)

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

now_mod = 0

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

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

print(-1)
exit()

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

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

ans = 1
n = 7%K
for _ in [0]*K:
    if n == 0:
        print(ans)
        break
    n = (n*10+7)%K
    ans += 1
else:
    print(-1)

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

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

else:
    print('-1')

Solution (Python):

import sys
input = sys.stdin.readline

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

print(-1)

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    k=INT()
    temp=7
    ans=-1
    for i in range(k):
        if i==0:
            temp=temp%k
        else:
            temp=(temp*10+7)%k

        if temp==0:
            ans=i+1
            break

    print(ans)
if __name__=='__main__':
    do()

Solution (Python):
import math
import pprint
import fractions
import collections
import itertools
from decimal import *
from collections import deque
from bisect import *
K=int(input())
flag=0
cnt=0
ans=0
for i in range(K):
    cnt=(cnt+7*pow(10,i,K))%K
    if cnt==0:
        flag=1
        ans=i+1
        break
if flag==0:
    print(-1)
else:
    print(ans)

Solution (Python):
from collections import defaultdict
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()
c = 1
d = 7 % K
D = defaultdict(int)
while True:
    if d == 0:
        print(c)
        exit()
    if D[d] == 1:
        print(-1)
        exit()
    D[d] += 1
    c += 1
    d = (d * 10 + 7)%K

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

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

Solution (Python):
K = int(input())
ans = 1
now = 7
while now % K != 0:
    ans += 1
    now *= 10
    now += 7
    now %= K
    if ans > 999982:
        print(-1)
        exit()
print(ans)

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

x = 7 % k
s = set()
for i in range(k):
    if x % k == 0:
        ans = i + 1
        break
    if x in s:
        ans = -1
        break

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

print(ans)

Solution (Python):
import math
import sys
from itertools import permutations
input = sys.stdin.readline

K=int(input())

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

print(ans)

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

Solution (Python):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def main():
    k = int(input())
    a = 7
    x = 1
    while a % k != 0 and x <= k + 10:
        x += 1
        a = (a * 10 + 7) % k
    if x < k + 5:
        print(x)
    else:
        print(-1)
main()

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

tmp=7
flag=False

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

Solution (Python):
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

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

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

K = int(input())

A = [-1]*(K+1)

ans = -1
t = 7 % K
for s in range(K+1):
    if t == 0:
        ans = s + 1
        break
    if A[t] != -1:
        break
    A[t] = 1
    t = (t*10 + 7) % K

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()

tmp = 7
ans = 1
p = 1
mo = tmp%K
checked = [0]*(10**6+1)
checked[mo] = 1
while mo != 0:
    mo = mo + 7*pow(10, p, K)
    mo %= K
    p += 1
    if checked[mo]:
        print(-1)
        break
    checked[mo] = 1
else:
    print(p)

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

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

    r = 7 % K
    idx = 1
    while r:
        r = (r * 10 + 7) % K
        idx += 1
        if idx > K:
            print(-1)
            return

    print(idx)


if __name__ == '__main__':
    main()

Solution (Python):
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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


def main():
	K = int(input())
	val = 0
	for i in range(10 ** 6 + 1):
		val = (val * 10 + 7) % K
		if val % K == 0:
			print(i + 1)
			return

	print(-1)


if __name__ == '__main__':
	main()

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





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






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


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)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


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


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





K = I()

now = 7%K
count = 1

while now:
  now *= 10
  now += 7
  now %= K
  count += 1
  if count > K*2:
    print(-1)
    exit()
  
print(count)

Solution (Python):
k = int(input())
rem = 7%k
alreadys = [False]*k
alreadys[rem] = True

ans = 1
while True:
    if rem == 0:
        print(ans)
        exit()
    ans += 1
    rem = (rem*10+7)%k
    if alreadys[rem]:
        print(-1)
        exit()
    alreadys[rem] = True

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

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

print(ans)

Solution (Python):
k = int(raw_input())
seen = set()
compute = 7 % k
count = 1
while(compute!= 0 and compute not in seen):
	count += 1
	seen.add(compute)
	compute *= 10
	compute += 7
	compute %= k
print count if compute == 0 else -1

Solution (Python):

k = int(input())
ans = 1
p = 7
used = {p: True}
while True:
    if p % k == 0:
        print(ans)
        exit()
    p = (p * 10 + 7) % k
    if p in used:
        print(-1)
        exit()
    used[p] = True
    ans += 1

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  


K = ni()

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

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