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

Solution (Python):
import sys


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


sys.setrecursionlimit(20000000)

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


def check(n):
    C = ["0", "1", "2", "3", "4", "5", "6", "8", "9"]
    for c in C:
        if c in str(n):
            return False
    return True


def main():
    K = int(input())
    if K % 2 == 0:
        print(-1)
        return
    if K % 5 == 0:
        print(-1)
        return
    if K % 7 == 0:
        L = 9 * K // 7
    else:
        L = 9 * K
    cnt = 1
    amari = 10 % L
    while True:
        if amari == 1:
            print(cnt)
            return
        amari = amari * 10 % L
        cnt += 1


if __name__ == "__main__":
    main()

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

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

Solution (Python):
k = int(input())
n = 10
cnt = 1
if k%2 == 0:
    print(-1)
elif k%5 == 0:
    print(-1)
else:
    if k%7== 0:
        x = 9*k//7
        while True:
            if n%x == 1:
                print(cnt)
                break
            else:
                n = n%x*10%x
                cnt += 1
    else:
        x = 9*k
        while True:
            if n%x == 1:
                print(cnt)
                break
            else:
                n = n%x*10%x
                cnt += 1

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

Solution (Python):




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

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


if __name__ == "__main__":
    main()

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

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

    mod = (10*mod + 7) % K

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

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




if N % 2 == 0 or N % 5 == 0:
    print(-1)
    exit()
i = 0
num = 0
while True:
    num = (num * 10 + 7) % N
    i += 1
    if num == 0:
        print(i)
        exit()

K = int(input())

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

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

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

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

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

Solution (Python):
def main():
    k = int(input())
    x = 0
    flag = True
    
    
    
    
    
    
    
    
    mod = 1
    for i in range(1, 10**6+1):
        mod *= 10
        if k % 7 == 0:
            mod = mod % (9*k/7)
            if mod == 1:
                print(i)
                flag = False
                break
        else:
            mod = mod % (9*k)
            if mod == 1:
                print(i)
                flag = False
                break

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

Solution (Python):
def f(K):
    sum = 0
    p10 = 1
    for i in range(K+1):
        sum += p10*7
        p10 *= 10
        p10 %= K
        sum %= K

        if sum == 0:
            return i+1
    return -1


K = int(input())

print(f(K))

Solution (Python):
def f(K):
    sum = 0
    for i in range(K+1):
        sum += (pow(10, i, K)*7)
        sum %= K

        if sum == 0:
            return i+1
    return -1


K = int(input())

print(f(K))

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

Solution (Python):
def gcd(a, b):
  if a < b:
    return gcd(b, a)
  if b == 0:
    return a
  return gcd(b, a%b)

K = int(input())

if gcd(K, 10) != 1:
  print(-1)
else:
  if K % 7 == 0:
    K//=7
  ans = 1
  cur = 1
  while cur % K != 0:
    cur += pow(10, ans, K)
    ans += 1
  print(ans)

Solution (Python):
def solve():
	n = int(input())
	if n%2 == 0 or n%5 == 0:
		return -1
	if n % 7 == 0:
		n//=7
	n*=9
	cnt = 1
	cur = 10
	while cur % n != 1:
		cur = (cur * 10)%n
		cnt+=1
	return cnt




print(solve())

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

Solution (Python):
import math

k = int(input())

count = 0
value = 0
remain_sum = 7
digit_remain = 7

while True:
    if count > k:
        print(-1)
        break
    if remain_sum % k == 0:
        print(count+1)
        break
    digit_remain = digit_remain * 10 % k
    remain_sum += digit_remain

    count += 1

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

rem = 7%K

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

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

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

num=7
num%=k
ans=1

while num!=0:
  num=10*num+7
  num%=k
  ans+=1

print(ans)

Solution (Python):


k=int(input())

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

Solution (Python):


k=int(input())

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

Solution (Python):


k=int(input())


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

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

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

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

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

ans=1
q=10%l

while q!=1:
  q*=10
  q%=l
  ans+=1

print(ans)

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

Solution (Python):
K=int(input())
num=7
count = 0
checkK = [0 for j in range(K)]
result = ""

flag = True
while(flag):
    count += 1
    if num%K==0:
        flag = False
        result = str(count)
    num = (num*10+7)%K
    checkK[num] += 1
    if checkK[num] == 2:
        flag = False
        result = "-1"
print(result)

Solution (Python):


from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


K = int(input())
















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

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

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

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

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

print(ans)

Solution (Python):







k = int(input())

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

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

Solution (Python):
import math
k=int(input())
if k%7==0:k//=7
if math.gcd(10,k)!=1: exit(print(-1))
if k==1: exit(print(1))
v=1
ans=0
while(v!=0):
    v=(v*10+1)%k
    ans+=1 
print(ans+1)

Solution (Python):

import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline





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

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

Solution (Python):
k = int(input())
if k % 10 in [0, 2, 4, 5, 6, 8]:
  print("-1")
else:
  c = 1
  r = 7 % k
  while True:
    if r == 0:
      break
    else:
      c += 1
      r = (10*r+7) % k
  print(c)

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

Solution (Python):



















"""fact=[1]












from sys import stdin, stdout
import bisect            
from bisect import bisect_left as bl              
from bisect import bisect_right as br             
import itertools
from collections import Counter

import collections
import math
import heapq
import re
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
  
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l

def most_frequent(list):
    return max(set(list), key = list.count) 
def GCD(x,y):
    while(y):
        x, y = y, x % y
    return x

def ncr(n,r,p):                                              
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t

def Convert(string): 
    li = list(string.split("")) 
    return li 

def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
prime=[]
q=[]
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            
    return j







"""*******************************************************"""
def main():
        n=inin()
        cnt=1
        temp=0
        z=0
        flag=0
        while cnt<=n:
            
            z=(10*z+7)%n
            if z==0:
                print(cnt)
                flag=1
                break
            cnt+=1
        if flag==0:
            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):



















"""fact=[1]












from sys import stdin, stdout
import bisect            
from bisect import bisect_left as bl              
from bisect import bisect_right as br             
import itertools
from collections import Counter

import collections
import math
import heapq
import re
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
  
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l

def most_frequent(list):
    return max(set(list), key = list.count) 
def GCD(x,y):
    while(y):
        x, y = y, x % y
    return x

def ncr(n,r,p):                                              
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t

def Convert(string): 
    li = list(string.split("")) 
    return li 

def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
prime=[]
q=[]
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            
    return j







"""*******************************************************"""
def main():
    n=inin()
    if n&1==0:
        print(-1)
    else:
        cnt=1
        temp=0
        z=0
        flag=0
        while cnt<=n:
            
            z=(10*z+7)%n
            if z==0:
                print(cnt)
                flag=1
                break
            cnt+=1
        if flag==0:
            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):
def resolve():
    '''
    code here
    '''
    K = int(input())

    is_not_found = True
    memo = [0 for _ in range(K)]

    i=7%K
    res = 1
    if i == 0:
        is_not_found = False

    while is_not_found and memo[i] == 0:
        memo[i] += 1
        if i == 0:
            is_not_found = False
        else:
            res += 1
            i = (i * 10 + 7) % K

    print(res) if is_not_found == False else print(-1)


if __name__ == "__main__":
    resolve()

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

L = 9 * K

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

power = 1

for i in range(1, 10 ** 6):
    power *= 10
    power %= L
    if power == 1:
        print(i)
        sys.exit()

print(-1)

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)

m = 10

for i in range(k):
    m = m % L
    if m == 1:
        print(i + 1)
        exit()
    else:
        m = m * 10

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

s=0
i = 1
while i <=K:
    s = (s*10+7)%K
    if s==0:
        print(i)
        break
    i +=1
if i>K:
    print(-1)

Solution (Python):


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

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

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


if __name__ == '__main__':
    main()

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

Solution (Python):




from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

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

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

x = 7 % K
for i in range(K):
    if x == 0:
        print(i + 1)
        break
    x = x * 10 + 7
    x = x % K
else:
    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)
        exit()
print(-1)

Solution (Python):



K=int(input())

modsevens=[7]

if K==7 or K==1:
    print(1)
    exit()
else:
    pass

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

print(-1)

Solution (Python):



K=int(input())

modsevens=[7]

if K==7 or K==1:
    print(1)
    exit()
else:
    pass

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

print(-1)

Solution (Python):

K = int(input())
if K % 7 == 0:
  K = K // 7
K = 9 * K
remain = 1
for i in range(10**6):
  remain = (remain*10) % K
  if remain == 1:
    print(i+1)
    break
else:
  print(-1)

Solution (Python):


from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


K = int(input())















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

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

cur = 7
flg = False
for i in range(10 ** 6):
    mod = cur % K
    if mod == 0:
        ans = i + 1
        flg = True
        break
    else:
        cur = mod * 10 + 7

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

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

seen = [0]*(k+1)
rem=0
for i in range(0,k+1):
    rem = (rem*10+7) % k
    
    if rem == 0:
        print(i + 1)
        break
    elif seen[rem] ==1:
        print('-1')
        break
    else:
        seen[rem] =1

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:
    i = 1
    num = 10
    while True:
        num = num % L
        if num == 1:
            break
        else:
            i += 1
            num *= 10

    print(i)

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

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

tmpNum = 7
count = 1
keisuu = 10

tmp = tmpNum%K
aa = tmp
while tmp !=0 and count<=K:
    aa = (aa*10)%K
    tmp = (tmp+aa)%K
    count+=1

if count>K:
    count=-1

print(count)

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

Solution (Python):
K = int(input())
ref = 0
ans = 0

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

print(ans)

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

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

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

Solution (Python):
def power(x, n, mod):
    ans = 1
    while n > 0:
        if n % 2 == 1:
            ans = ans * x % mod
        n //= 2
        x = x * x % mod
    return ans

def eular(n):
    ans = 1
    if n % 2 == 0:
        x = 1
        while n % 2 == 0:
            n //= 2
            x *= 2
        ans *= x - x // 2
    i = 3
    while i * i <= n:
        if n % i == 0:
            x = 1
            while n % i == 0:
                n //= i
                x *= i
            ans *= x - x // i
        i += 2
    if n != 1:
        ans *= n - 1
    return ans

k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
    quit()
elif k % 7 == 0:
    l = 9 * k // 7
else:
    l = 9 * k

phi_l = eular(l)
ans = phi_l
d, x = 10, 1
while x * x <= phi_l:
    if phi_l % x == 0:
        if d % l == 1:
            ans = x
            break
        else:
            y = phi_l // x
            if pow(10, y, l) == 1:
                ans = y
    d = d * 10 % l
    x += 1
print(ans)

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

if K%2 == 0 or K%5 == 0:
    print(-1)
else:
    if K%7 == 0:
        L = 9*K//7
    else:
        L = 9*K
    i = 1
    A = 10
    while i < 9000000:
        re = A%L
        if re == 1:
            print(i)
            break
        else:
            A = re*10
            i += 1
    else:
        print(-1)

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

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

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd


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

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

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

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

while (not x in s):
    if x == 0:
        print(i)
        exit()
    s.add(x)
    x = (x*10+7) % k
    i += 1
print(-1)

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

sevens = 0
count = 0
repeat = True

if {K%10} & {0,2,4,5,6,8}:
    count = -1
    repeat = False

while repeat:
    sevens = sevens % K * 10 + 7
    count += 1
    if sevens % K == 0:
        repeat = False

print(count)

Solution (Python):
k = int(input())
has = [False] * k
ans = 1
num = 7 % k

while num != 0 and not has[num]:
    has[num] = True
    num = (num * 10 + 7) % k
    ans += 1
    
if num == 0:
    print(ans)
else:
    print(-1)

Solution (Python):
if __name__ == '__main__':

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

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

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

if K == 1:
    print(1)
elif K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    if K % 7 == 0:
        L = 9 * K // 7
    else:
        L = 9 * K
    
    b = 10 % L
    for i in range(1, 1000000):
        if b == 1:
            print(i)
            break
        else:
            b = (10 * b) % L

Solution (Python):


k = int(input())
n = 7 % k

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

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):
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())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    c = 7
    count = 1
    while True:
        if c % k == 0:
            print(count)
            break
        else:
            c = (10 * c + 7) % k
            count += 1

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

if K % 2 == 0:
    print(-1)
elif K % 5 == 0:
    print(-1)
else:
    seven = 7
    ans = 1
    while ans < 1000000:
        amari = seven % K
        if amari == 0:
            print(ans)
            break
        else:
            ans += 1
            seven = amari * 10 + 7
    else:
        print(-1)

Solution (Python):
if __name__ == '__main__':

	k = int(input())

	

	s = set()
	x = 7 % k
	i = 1
	cnt = -1
	while x not in s:
		if x == 0:
			cnt = i
			break
		s.add(x)
		x = (10 * x + 7) % k
		i += 1

	print(cnt)

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

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

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

Solution (Python):









K = int(input())

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
















ans = -1
amari = 1
for n in range(1,2*10**8):
    amari = (10*amari)%L
    if amari == 1:
        ans = n
        break

print(ans)

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

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

print(i + 1)

Solution (Python):
'''
参考
https://qiita.com/c-yan/items/d1b19114d411755f25b5
https://qiita.com/easychoco/items/7f1f00d9221bd3ab0a6c
数列は以下で表すことができる
a[n+1] = a[n] * 10 + 7
a[n] % K == 0となれば、その時点でのnが解となる
'''
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

num = 0

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

print(-1)

Solution (Python):


def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\n
        int: 標準入力
    """
    K = int(input())

    return K


def main(K: int) -> None:
    """
    メイン処理.

    Args:\n
        K (int): 整数（1 <= K <= 10^6）
    """
    
    ans = -1
    remainder = 7 % K
    for i in range(1, 9000000):
        if remainder == 0:
            ans = i
            break
        remainder = (10 * remainder + 7) % K

    
    print(ans)


if __name__ == "__main__":
    
    K = get_input()

    
    main(K)

Solution (Python):


K = int(input())


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


print(ans)

Solution (Python):
from sys import exit



from collections import deque, Counter


(K,) = map(int, input().split())

q = Counter([])
tmp = K

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


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

tmp = 10

for i in range(1, 10 ** 9):
    if tmp > L:
        tmp = tmp % L
    if tmp % L == 1:
        print(i)
        exit()
    tmp *= 10

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

K = int(input())

val = 7
for n in range(1000010):
    val %= K
    if val == 0:
        print(n + 1)
        sys.exit(0)
    val *= 10
    val += 7

print(-1)

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

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