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 ** 9)

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

if __name__ == '__main__':
    main()

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

N=7%K
NotFound = True

for i in range(K):
  if N == 0:
    NotFound = False
    print(i+1)
    break
  N=(N*10+7)%K

if (NotFound):
  print(-1)

Solution (Python):
from sys import stdin
input = stdin.readline
ri = lambda : int(input())
ril = lambda : list(map(int, input().split()))

def main():
  K = ri()
  m = 0
  ans = -1
  for i in range(K):
    m = (10 * m + 7) % K
    if m == 0:
      ans = i + 1
      break
  print(ans)

if __name__ == '__main__':
  main()

Solution (Python):
k = int(input())
cnt = 1
num = 7

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

while 1:
  num %= k
  if num == 0:
    break
  num = num*10+7
  cnt += 1
  
print(cnt)

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

for count in range(1, K+1):
  num = base*10 + 7
  if (num%K == 0):
    print(count)
    exit()
  else:
    base = num%K
print(-1)

Solution (Python):
k = int(input())
ans = -1
seq = [0]

seq.append(7%k)
for i in range(2,k+1):
  seq.append((seq[i-1]*10+7)%k)

for j in range(1,k+1):
  if seq[j] == 0:
    ans = j
    break

print(ans)

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


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

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

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

mod_first = 7 % N
mod_next = mod_first * 11 % N

if mod_first == 0:
    print("1")
    exit()
if mod_next == 0:
    print("2")
    exit()

for i in range(10000000):
    mod_next = (mod_next * 10 + mod_first) % N
    if mod_next == 0:
        print(i + 3)
        exit()

print("-1")

Solution (Python):
def abc174_c():
    k = int(input())
    ans = -1
    if k % 2 == 0 or k % 5 == 0:
        return ans
    f = 0
    for i in range(k+1):
        f = (f * 10 + 7) % k
        if f == 0:
            ans = i + 1
            break
    return ans

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

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

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

m = set()
x = 7
ans = 1
while x > 0:
    if x < K:
        x = x*10 + 7
        ans += 1
    x = x % K
    if x in m:
        print(-1)
        exit(0)
    else:
        m.add(x)

print(ans)

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

Solution (Python):
k= int(input())
a = 7 % k
a_list = [a]
for _ in range(k):
    an = a_list[-1]
    a_list.append((10*an+7)%k)
for ind, num in enumerate(a_list):
    if num == 0:
        print(ind+1)
        break
    if ind == k-1:
        print(-1)

Solution (Python):
def main():
    k = int(input())
    init = 7%k
    an = [init]
    for _ in range(k):
        a = an[-1]
        an.append((10*a+7) % k)

    for ind, a in enumerate(an):
        if a==0:
            print(ind+1)
            return
    print(-1)
if __name__ == '__main__':
    main()

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

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

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

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):
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    k = ri()
    if k % 2 == 0 or k % 5 == 0:
        print (-1)
        return
    else:
        rem = 7 % k
        power = 1
        while rem != 0:
            rem = (10 * rem + 7) % k
            power += 1
        print (power)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()

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

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

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

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

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

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

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

Solution (Python):
N=int(input())
if N%2==0:
  print(-1)
elif N%5==0:
  print(-1)
else:
  ans=1
  a=7
  num=7
  while(num%N!=0):
    a=(a*10)%N
    num=(num+a)%N
    ans+=1
  print(ans)

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

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

a = [0] * (K + 2)
a[0] = 7%K

for i in range(1, K + 1):
    a[i] = (a[i-1]*10 + 7) % K

f = 0

for i in range(K + 1):
    if a[i] == 0:
        print(i + 1)
        f = 1
        break

if f == 0:
    print("-1")

Solution (Python):
K = int(input())
amaris = [0]*(K)
num = 7
answer = -1
count = 1
while True:
    amari = num%K
    if amari == 0:
        answer = count
        break
    if amaris[amari] == 0:
        amaris[amari] = 1
    else:
        break
    num = 10*amari + 7
    count += 1
print(answer)

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

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

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

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

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

t = 7

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

print(-1)

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

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

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

print(-1)

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

Solution (Python):
import sys
K=int(sys.stdin.readline().strip())
a=0
for i in range(10**6):
    a+=7*pow(10,i,K)
    a%=K
    if a==0:
        print i+1
        quit()
else:
    print -1

Solution (Python):
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

K = I()

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

a = [0] * 10**7
a[0] = 7%K

for i in range(1, K+1):
    a[i] = (a[i-1] * 10 + 7) % K

for i in range(K+1):
    if a[i] == 0:
        print(i+1)
        exit()

print(-1)

Solution (Python):
import sys
k=int(input())
l=[]
x=7%k
if x == 0:
  print(1)
  sys.exit()
for i in range(2,k+1):
  num=(x*10+7)%k
  x=num
  l.append(num)
  if num==0:
    print(i)
    break
if 0 not in l:
  print(-1)

Solution (Python):
K = int(input())
used = set()
pos = 1
v = 0

while 1:
    v = (10*v+7)%K
    if v==0:
        print(pos)
        break
    if v in used:
        print(-1)
        break
    used.add(v)
    pos += 1

Solution (Python):
K = int(input())
used = set()
pos = 1
v = 0

while 1:
    v += 7*pow(10, pos-1, K)
    v %= K
    if v==0:
        print(pos)
        break
    if v in used:
        print(-1)
        break
    used.add(v)
    pos += 1

Solution (Python):
from sys import stdin
K = int(stdin.readline().rstrip())
def main(K):
  a=0
  for i in range(1,K+1):
    a = ((10%K) * a + 7)%K
    if a == 0:
      return i
  return -1
print(main(K))

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

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

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

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

print(ans)

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

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

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

remain = 7 % K
set_remain = set()
while (True):
    count += 1
    if remain == 0:
        print(count)
        exit()
    if remain in set_remain:
        break
    else:
        set_remain.add(remain)
    remain = (remain * 10 + 7) % K

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

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())
ans = 1
mod = 7

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

Solution (Python):
def calc(k):
  cur = 0
  for i in range(1, 10 ** 7):
    cur *= 10
    cur += 7
    cur %= k
    if cur == 0:
      return i
  return -1

k = int(input())
print(calc(k))

Solution (Python):
k = int(input())
lis = []
c = 1
a = 0
while(True):
    a = (a*10 + 7) % k
    if a == 0:
        print(c)
        quit()
    if c > k:
        print(-1)
        quit()
    c += 1

Solution (Python):



K = int(input())

s = 7 % K
for i in range(1, K+1) : 
    if i != 1 : 
        s = (10*s + 7) % K

    if s == 0 : 
        print(i)
        exit()

print(-1)

Solution (Python):
K = int(input())
r = 7
ans = 1
s = set([])
while True:
    r %= K
    if r == 0:
        print(ans)
        break
    if r in s:
        print(-1)
        break
    s.add(r)
    r *= 10
    r += 7
    ans += 1

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

K = k()
m = 0

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

print('-1')

Solution (Python):

def main():
    import sys
    imput = sys.stdin.readline
    
    
    
    k = int(input())

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

Solution (Python):

def main():
    import sys
    imput = sys.stdin.readline
    
    
    
    k = int(input())

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

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

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

Solution (Python):
def main():

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

if __name__ == '__main__':
    main()

Solution (Python):
K=int(input())
def waru(K):
    a=[]
    if K%2==0 or K%5==0:
        print("-1")
        return
    a.append(7%K)
    for i in range(1,K):
        a.append((10*a[i-1]+7)%K)
    for i in range(K):
        if a[i]==0:
            print(i+1)
            return
    print(-1)
waru(K)

Solution (Python):
def c_repsept_totient():
    def euler_phi(n):
        """正整数 n に対して、n と互いに素な n 以下の正整数の個数"""
        ret = n
        for i in range(2, int(n**0.5) + 1):
            if n % i == 0:
                ret = ret // i * (i - 1)
                while n % i == 0:
                    n //= i
        if n > 1:
            ret -= ret // n
        return ret

    def divisor_list(n):
        """n の正の約数のリスト"""
        ret = set()
        for k in range(1, int(n**0.5) + 1):
            if n % k == 0:
                ret.update({k, n // k})
        return sorted(ret)

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

    for d in divisor_list(euler_phi(L)):
        if pow(10, d, L) == 1:
            return d
    return -1

print(c_repsept_totient())

Solution (Python):
import sys

k = int(input())
s = set()

x = 7%k
i = 1

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

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

Solution (Python):
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
    dprint = print
else:
    def dprint(*args):
        pass

k = list(map(int, input().split()))[0]

modk = 7 % k
i = 1
while(i < k):
    if modk == 0:
        print(i)
        exit()

    i += 1
    modk = (modk * 10 + 7) % k
else:
    if modk == 0:
        print(i)
    else:
        print(-1)

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

Solution (Python):
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
    dprint = print
else:
    def dprint(*args):
        pass

k = list(map(int, input().split()))[0]

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

    modk = (modk * 10 + 7) % k
else:
    print(-1)

Solution (Python):
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
    dprint = print
else:
    def dprint(*args):
        pass

k = list(map(int, input().split()))[0]

am = 7 % k
i = 1

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

Solution (Python):
import sys
import math
import time
sys.setrecursionlimit(int(1e6))
if False:
    dprint = print
else:
    def dprint(*args):
        pass

k = list(map(int, input().split()))[0]

if (k % 7 == 0):
    l = 9*k/7
else:
    l = 9*k
dprint('k, l = ', k, l)

i = 1
n = 10
while(i < 10**6):
    m = n % l
    if (m == 1): 
        print(i)
        exit()
    dprint('i, n, m = ', i, n, m)

    i = i + 1
    n = m * 10
else:
    print(-1)

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

am=7%k
i=1

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

print('-1')

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

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

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

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

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

for i in range(ku):
    if i == 0:
        b[i] = 7%k
    else:
        b[i] = (b[i-1]*10+7)%k

if 0 in b:
    print(b.index(0)+1)
else:
    print(-1)

Solution (Python):
k = int(input())
dp = [0 for _ in range(k+100)]
good = False
for i in range(1, k+1):
    dp[i] = (dp[i-1] * 10 + 7) % k
    if dp[i] % k == 0:
        print(i)
        good = True
        break
if not(good):
    print(-1)

Solution (Python):

K = int(input())
count = 1
a = 7 % K

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

print (-1)

Solution (Python):
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


















def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


mod=1000000007
def combinations_count_mod(n, r):
    r = min(r, n - r)
    numer = reduce(lambda x,y: x*y%mod, range(n, n - r, -1), 1)
    denom = pow( reduce(lambda x,y: x*y%mod, range(1, r + 1), 1) , mod-2, mod)
    return numer * denom % mod


def solve(k):
    dp=[0 for _ in range(k+100)]
    for i in range(1,k+1):
        dp[i]=(dp[i-1]*10+7)%k
        if dp[i]%k==0:
            return (i)
    return -1

def main():
    k = int(input().strip())
    print(solve(k))


if __name__ == '__main__':
    main()

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

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

Solution (Python):
from __future__ import print_function

from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


















def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


mod = 1000000007


def combinations_count_mod(n, r):
    r = min(r, n - r)
    numer = reduce(lambda x, y: x*y % mod, range(n, n - r, -1), 1)
    denom = pow(reduce(lambda x, y: x*y % mod, range(1, r + 1), 1), mod-2, mod)
    return numer * denom % mod









a_init=7
def solve(K):
    if K%2==0 or K%5==0:
        return -1
    elif a_init%K==0:
        return 1
    else:
        dp=[a_init%K]+[0 for _ in range(K)]
        for i in range(1,K+100):
            dp[i]=(dp[i-1]*10+a_init)%K
            if dp[i]%K==0:
                return (i+1)
        return -1

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

if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())
mod = 7
index = 1
flag = 0

if K % 2 == 0:
  print(-1)
elif K % 5 == 0:
  print(-1)
else:  
  while(index<=K):
      mod=mod%K
      if mod==0:
          print(index)
          flag=1
          break
      mod=mod*10+7
      index+=1
  if flag==0:
      print(-1)

Solution (Python):
n = int(input())
ans = 7
cnt = 1

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

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

Solution (Python):
K=int(input())
mod=7
index=1
flag=0
while(index<=K):
    mod=mod%K
    if mod==0:
        print(index)
        flag=1
        break
    mod=mod*10+7
    index+=1
if flag==0:
    print(-1)

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

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

Solution (Python):
def phi(n):
    res = n
    i = 2
    while i * i <= n:
        if n % i == 0:
            res = res // i * (i - 1)
            while n % i == 0:
                n //= i
        i += 1
    if n != 1:
        res = res // n * (n - 1)
    return res


def divisors(n):
    sq = int(n ** .5)
    res = ((i, n // i) for i in range(1, sq + 1) if n % i == 0)
    from itertools import chain
    flatten = chain.from_iterable
    return sorted(set(flatten(res)))


def f(K):
    L = 9 * K
    if K % 7 == 0:
        L //= 7
    r1 = phi(L)
    for d in divisors(r1):
        if pow(10, d, L) == 1:
            return d
    return -1



if __name__ == '__main__':
    K = int(input())
    res = f(K)
    print(res)

Solution (Python):
K=int(input())
ans=-1
i=1
now=7
while i<=10**6:
    now%=K
    if now==0:
        ans=i
        break
    now+=7*pow(10,i,K)
    i+=1
print(ans)

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain, product
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):
    return fs[n] * invs[n-k] * invs[k] % modp



class UnionFindEx:
    def __init__(self, size):
        
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'



def main():
    K = ii()
    n = 7%K
    s = set()
    for i in range(1, K+10):
        if n == 0:
            print(i)
            return
        n = (10*n + 7) % K
        if n in s:
            print(-1)
            return
        s.add(n)






main()

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

Solution (Python):
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    k = ii()
    done = [0 for i in range(k + 10)]
    tmp = 0
    cnt = 0
    while True:
        cnt += 1
        tmp *= 10
        tmp += 7
        tmp %= k
        if done[tmp]:
            print(-1)
            exit()
        if tmp == 0:
            print(cnt)
            exit()
        done[tmp] = 1


main()

Solution (Python):
from collections import Counter
import copy
from itertools import combinations


def A(x):
  return 'Yes' if x >= 30 else 'No'


def B(N, D, X, Y):
  ans = 0
  for i in range(N):
    Di = X[i]**2 + Y[i]**2
    if Di <= D**2:
      ans += 1
  return ans


def C(K):
  mods = [0] * 1000001
  mod = 7 % K
  if mod == 0:
    return 1
  num_iters = 1
  while mods[mod] == 0:
    mods[mod] = 1
    mod = (mod * 10 + 7) % K
    num_iters += 1
    if mod == 0:
      return num_iters
  return -1


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


if __name__ == '__main__':
  main()

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

Solution (Python):

def get_mod(prev_mod):
	global K
	
	return (prev_mod * 10 + 7) % K


K = int(input())
mod = 0
count = 0
mods = set()

while True:
	mod = get_mod(mod)
	count += 1
	
	if mod == 0:
		print(count)
		break
	else:
		if mod in mods:
			print(-1)
			break
		else:
			mods.add(mod)

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

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

Solution (Python):


def main():
    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")
        return 0
        
    for i in range(1, 10**6):
        if i == 1:
            tmp = 10 % l
        else:
            tmp = (tmp * 10) % l
            
        if tmp == 1:
            print(i)
            return 0
    
main()

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

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

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

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

print(ans)

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

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

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

if __name__ == "__main__":
    main()