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())
x = 7 % k
for i in range(1, k + 10):
    if not x:
        print(i)
        exit()
    x = (10 * x + 7) % k
print(-1)

Solution (Python):
K = int(input())
x = 7%K
ans = -1

for n in range(1,K+10):
    if x==0:
        ans = n
        break

    x = (x * 10 + 7)%K
print(ans)

Solution (Python):
K=int(input())
 
j=0
ans=0
a=0
while True:
    a=a*10+7
    a=a%K
    ans+=1
    
    if a==0:
        break
    
    if ans>K:
        ans=-1
        break
 
print(ans)

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

ch=7%k
flag=0
for i in range(1,10000001):
    if ch%k==0:
        print(i)
        flag=1
        break
    ch=(ch*10+7)%k
    
if not flag:
    print("-1")

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

Solution (Python):
import sys

input = sys.stdin.readline
k = int(input())
num = 7%k
soln = False
for i in range(1, k+1):
    if num == 0: print(i); soln = 1; break
    num = ((((num%k) * (10%k))%k) + (7%k))%k
if not soln: print(-1)

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

def func(k):
    number = 7 % k
    for i in range(k):
        if number == 0:
            return i+1
        number = (10 *number + 7) % k 
    return -1
    
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    print(func(k))

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):
import sys, 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()

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

    tmp = 7
    count = 1        

    while count < 10 ** 6:
        tmp %= k
        if tmp == 0:
            print(count)
            exit()
        count += 1
        tmp = tmp * 10  + 7

    print(-1)

if __name__ == '__main__':
    main()

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

Solution (Python):
k=int(input())
x=i=0
while i<k:i+=1;x=(x*10+7)%k;x<1>exit(print(i))
print(-1)

Solution (Python):
k=int(input())
x=i=0
while i<k:i+=1;x=(x*10+7)%k;x<1>exit(print(i))
print(-1)

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

Solution (Python):
k=int(input())
x=i=0
while i<7e6:i+=1;x=(x*10+7)%k;x<1>exit(print(i))
print(-1)

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

Solution (Python):
import sys

input = sys.stdin.readline

k = int(input())
'''if k == 7 or k == 1:
    print(1)
elif k % 2 == 0 or k % 5 == 0: print(-1)
else:
    if k % 7 == 0: k = k // 7
    mod = 9*k
    i = 1;
    result = 10;
    while result != 1:
        result = (result * 10) % mod
        i += 1
    print(i)'''
num = 7%k
soln = False
for i in range(1, k+1):
    if num == 0:
        print(i)
        soln = True
        break
    num= (num * 10 + 7) % k
if not soln:
    print(-1)

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

x = 7 % K
s = set()
count = 0
while(True):
    count += 1
    if x in s:
        print(-1)
        break
    else:
        s.add(x)
        if x == 0:
            print(count)
            break
        x = (10*x+7) % K

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

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

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

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

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

Solution (Python):
K = int(input())
seven = 7
count = 0

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

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

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

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

memo = set()
repunit = 7%K
n = 1
while True:
    if repunit == 0:
        print(n)
        exit()
    else:
        if repunit in memo:
            print(-1)
            exit()
        else:
            memo.add(repunit)
    repunit = (repunit*10 + 7)%K
    n += 1

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

m = 0

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

print(-1)

Solution (Python):
import sys

K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    sys.exit()
if K % 7 == 0:
    K //= 7
count = 1
mod = 1
sum = 1
while sum % K != 0:
    mod = (mod * 10) % K
    sum += mod
    sum = sum % K
    count += 1
print(count)

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

m = 0

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

print(-1)

Solution (Python):
"""
    Satwik_Tiwari ;) .
    2ND AUGUST , 2020  - SUNDAY
"""



from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter  
from itertools import combinations as comb 
from itertools import permutations as permutate
from bisect import bisect_left as bl


from bisect import bisect_right as br
from bisect import bisect





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


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)





from types import GeneratorType
def iterative(f, stack=[]):
  def wrapped_func(*args, **kwargs):
    if stack: return f(*args, **kwargs)
    to = f(*args, **kwargs)
    while True:
      if type(to) is GeneratorType:
        stack.append(to)
        to = next(to)
        continue
      stack.pop()
      if not stack: break
      to = stack[-1].send(to)
    return to
  return wrapped_func





mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") 
def out(var): sys.stdout.write(str(var))  
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())

def zerolist(n): return [0]*n
def nextline(): out("\n")  
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True




def solve():
    k = int(inp())
    curr = str(7%k)
    for i in range(k):
        if(int(curr)%k==0):
            print(i+1)
            return
        else:
            curr+='7'
            curr = str(int(curr)%k)
    print(-1)


testcase(1)

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

ans = 1
X = 7
cnt = K

for _ in range(1000000):
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7

if x != 0:
    print(-1)

Solution (Python):
k = int(input())
c = 0
start = 7%k
while c<=k:
    if start == 0:
        break
    c+=1
    start = (start*10+7)%k
if c>k:
    print(-1)
else:
    print(c+1)

Solution (Python):
K = int(input())
 
ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 
 
if x != 0:
    print(-1)

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

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

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

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

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

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

ans = 1
X = 7
cnt = K

while ans <=K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7

if x != 0:
    print(-1)

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
def I(): return int(input())


def main():
    K = I()
    if K % 2 == 0 or K %  5 == 0:
        print(-1)
        exit()
    if K % 7 == 0:
        K = 9*K//7
    else:
        K = 9*K
    amari = 1
    for i in range(10**6):
        amari = amari*10 % K
        if amari == 1:
            print(i+1)
            exit()
    print(-1)

if __name__ == "__main__":
    main()

Solution (Python):




def is_valid(x):
    
    
    return str(x).count('7') == len(str(x))

def main():
    
    

    k = int(input())
    s = 7

    for i in range(1, int(1e6)+5):
        if s % k == 0:
            print(i)
            return
        s = (s * 10 + 7) % k
    print(-1)


py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

if __name__ == '__main__':
   main()

Solution (Python):
from numba import njit
k = int(input())

l = 0
if k % 7 == 0:
    l = 9 * k // 7
else:
    l = 9 * k

@njit
def fun():
    m = 1
    for i in range(1, l + 1):
        m = m * 10 % l
        if m == 1:
            print(i)
            break
    else:
        print(-1)

fun()

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


else:
    print("-1")

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

ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 

if x != 0:
    print(-1)

Solution (Python):
K = int(input())
x=7
ans = 0
if K%2!=0 and K%5!=0:
    for i in range(K+1):
        if x%K == 0:
            ans = 1
            break
        x = (x*10+7) % K
        
if ans == 1:
    print(i+1)
else:
    print(-1)

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

Solution (Python):
def main():
    k = int(input())
    num = 1
    n = 7

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

if __name__ == '__main__':
    main()

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

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

Solution (Python):
K = int(input())
i = 1
y = 1
if K== 1:
  print(1)
elif K%2 == 0 or K%5 == 0:
  print(-1)


elif K== 7:
  print(1)
else:
  if K%7 == 0:
    K = K//7
  while True:
    i += 1
    y = ((y*10)%K) + 1
    y = y%K
    if y == 0:
      break
  print(i)

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

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

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

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


for i in range(2*10**6):
  now=(10*mae+7)%k
  if now%k==0:
    print(i+1)
    sys.exit()
  else:
    mae=now%k

print(-1)

Solution (Python):
k=int(input())
mod=k
t=7
for i in range(k):
    if t%mod==0:
        print(i+1)
        exit()
    t%=mod
    t*=10
    t+=7
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)

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

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

  
  
print(-1)

Solution (Python):
from math import log10

K = int(input())
  
def find(K):
  if K % 2 == 0 or K % 5 == 0:
    return -1
  
  if K % 7 == 0:
    L = K * 9 // 7
  else:
    L = K * 9

  count = max(int(log10(L)), 1)
  
  quotient = 10**count % L
  
  while True:
    if quotient == 1:
      return count
    quotient = quotient * 10 % L
    count += 1
    
    
print(find(K))

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

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

count = 1
m = 7 % K
s = set()
while 1:
    if m == 0:
        print(count)
        break
    if m in s:
        print(-1)
        break
    count += 1
    s.add(m)
    m = (m * 10 + 7) % K

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

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

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

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

mod = [1]
i = 1


while True:
    mod.append((mod[i-1]*10)%L)
    if mod[i] == 1:
        print(i)
        break
    if i > K:
        print(-1)
        break
    i += 1

Solution (Python):
import sys

def resolve():
    readline=sys.stdin.readline
    k=int(readline())
    to=10**6
    svn=[0]*to
    svn[0]=7%k
    if svn[0]==0:
      print(1)
      return
    for i in range(1,to):
      svn[i]=(svn[i-1]*10)%k
    for i in range(1,to):
      svn[i]+=svn[i-1]
      if svn[i]%k==0:
        print(i+1)
        return
      
    print(-1)
    return
resolve()

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


if __name__ == "__main__":
    main()

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

digits = 1
remainder = 7 % k
while digits <= 1000000:
    if remainder == 0:
        print(digits)
        quit()
    digits += 1
    remainder = (remainder * 10 + 7) % k
print(-1)

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

Solution (Python):
n=int(input())
if n%2==0 or n%5==0:
    print(-1)
else:
    count=1
    flag=0
    num=7
    mod=7%n
    while flag==0:
        if mod==0:
            flag=1
        else:
            mod=(mod*10+7)%n
            count=count+1
    print(count)

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

    num = 1 
    n = 7
    
    if (k%2 == 0):
        print(-1)
        return
    

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

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

Solution (Python):
import sys

k = int(input())
n = 7
counter = 1
remainders = set()

while True:
    remainder = n % k
    if remainder == 0:
        print(counter)
        sys.exit()
    if remainder in remainders:
        print(-1)
        sys.exit()
    remainders.add(remainder)
    
    n = remainder * 10 + 7
    counter += 1

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

Solution (Python):
import sys
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()))

k = Ii()
if k%2 == 0 or k%5 == 0:
  print(-1)
  exit(0)
elif k%7 == 0:
  k = k//7
ans = 1
a = 10
mod = a%(9*k)
while mod != 1:
  mod *= 10
  mod = mod%(9*k)
  ans += 1
  
print(ans)

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

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

Solution (Python):
import math

def main():
    k = int(input())
    mod = 7
    cnt = 1

    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)

main()

Solution (Python):
import math
t = int(input())
if t%2==0 or t%5==0:
    print(-1)
else:
    i=1
    s=7%t
    while 1:
        if (s%t)==0:
            print(i)
            break
        i += 1

        s = (s * 10 + 7)%t

        continue

Solution (Python):
import math

k = int(input())

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

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

Solution (Python):
import sys

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

exists = set()
v = 7
if v % K == 0:
    print(1)
    sys.exit()
v %= K
for i in range(K):
     v = (v * 10 + 7) % K
     if v == 0:
        print(i+2)
        sys.exit()
     if v in exists:
        print(-1)
        sys.exit()
     exists.add(v)

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

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

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

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

else:
    num=7%k
    ans=1

    while num != 0:

        num=(num*10+7)%k
        ans+=1

    print(ans)

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

k = inint()

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

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

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

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