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

DEBUG=False
if DEBUG:
    f=open("C_input.txt")
else:
    f=sys.stdin
mod=1
ans=0
N=int(f.readline().strip())
if N%2==0 or N%5==0:
    print("-1")
else:
    if N%7==0:
        A=N*9/7
    else:
        A=N*9
    while True:
        ans+=1
        mod=(10*mod)%A
        if mod==1:
            print(ans)
            break
f.close()

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

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

Solution (Python):

_INPUT = """\
101
"""

def main():
    
    
    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)

if __name__ == '__main__':
    import io
    import sys
    import math

    
    main()

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

Solution (Python):
def solve(k):
    a_mod = 0
    pow_10 = 7
    for i in range(1000000):
        a_mod += pow_10
        a_mod %= k
        if a_mod == 0:
            return i + 1
        pow_10 *= 10
        pow_10 %= k
    return -1


def main():
    k = int(input())
    res = solve(k)
    print(res)


def test():
    assert solve(101) == 4
    assert solve(2) == -1
    assert solve(999983) == 999982


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

Solution (Python):
def solve(k):
    a_mod = 0
    for i in range(1000000):
        a_mod += 7 * pow(10, i, k)
        a_mod %= k
        if a_mod == 0:
            return i + 1
    return -1


def main():
    k = int(input())
    res = solve(k)
    print(res)


def test():
    assert solve(101) == 4
    assert solve(2) == -1
    assert solve(999983) == 999982


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

Solution (Python):


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

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

s = set()
seven = 7
ans = 1
while seven % K != 0:
    seven = seven * 10 + 7
    seven %= K
    if seven in s:
        ans = -1
        break
    s.add(seven)
    ans += 1

print(ans)

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

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

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

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

Solution (Python):
K = int(input())
ans = -1
a = [7 % K]
for i in range(1, K):
    a.append((a[i - 1] * 10 + 7) % K)
for i, n in enumerate(a, 1):
    if n == 0:
        ans = i
        break
print(ans)

Solution (Python):
'''
Date         : 2020-08-08 23:01:16
Author       : ssyze
Description  : 
'''
from math import *
k = int(input())
x = 7
cnt = 1
while x % k != 0:
    x = (x * 10 + 7) % k
    cnt += 1
    if cnt >= 10**6 + 5:
        break
if cnt >= 10**6 + 5:
    print("-1")
else:
    print(cnt)

Solution (Python):
import sys


a = int(input())

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

Solution (Python):



def main():
  k = int(input())
  a = 0
  for i in range(k):
    a = (10 * a + 7) % k
    if a == 0:
      print(i+1)
      return 
  print(-1)
  
if __name__=='__main__':
  main()

Solution (Python):
import functools

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

mod=0

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

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

if K%2==0:
    print(-1)
    exit(0)
    
ans=[0]*(pow(10,6)+1)
ans[0]=0

for i in range(1,pow(10,6)):
    ans[i]=(ans[i-1]*10+7)%K
    if ans[i]==0:
        print(i)
        exit(0)

print(-1)

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

    mod = 0

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

    print(-1)


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
input = sys.stdin.readline
K = int(input())
seven = 7 % K
c = 0
p = 1 % K
found = False
for i in range(K + 1):
  c = (c + p % K) % K
  if ((seven * c) % K == 0):
    found = True
    print(i + 1)
    break
  p = (p * (10 % K) ) % K
  

if not found:
  print(-1)

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

    m = 7 % K

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

if __name__ == "__main__":
    resolve()

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

def main():
    
    K = I()
    if K%2 == 0:
        print('-1')
        sys.exit()
    
    ans = 1
    n = 7
    for i in range(K):
        
        if n%K ==0:
            print(ans)
            break
        
        n = (10*n + 7)%K  
        ans += 1
    
    else:
        print('-1')

main()

Solution (Python):

k = int(input())

surplus = 0
ans = 1
while 1:
    if ans > k:
        print(-1)
        exit()
    surplus = ((surplus * 10) + 7) % k
    if surplus == 0:
        break
    ans += 1
print(ans)

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

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

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

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

Solution (Python):
def calc_term(k):
    
    power_ten_mod_k = [1] * k
    for i in range(1, k):
        power_ten_mod_k[i] = (10 * power_ten_mod_k[i-1]) % k
    
    one_consec_mod_k = power_ten_mod_k[:]
    for i in range(1, k):
        one_consec_mod_k[i] = (one_consec_mod_k[i] + one_consec_mod_k[i-1]) % k
    for i in range(k):
        if one_consec_mod_k[i] == 0:
            return i + 1
    return -1
    


def main():
    k = int(input())
    if k % 7 == 0:
        k //= 7
    if k == 1:
        print(1)
    else:
        print(calc_term(k))


if __name__ == '__main__':
    main()

Solution (Python):






















k = int(input())

if k % 2 == 0:
    print(-1)
else:
    count = 1
    if k == 1 or k == 7:
        print(1)
    else:
        now = 7 % k
        while (1):
            count += 1
            now = ((now * 10 + 7) % k) % k
            if now == 0:
                print(count)
                exit()
            if count >= 1000000:
                print(-1)
                exit()

Solution (Python):
k = int(input())
ans = 1
seen = set()
mod = 7%k
while mod != 0 and mod not in seen:
    seen.add(mod)
    mod = (10*mod + 7)%k
    ans += 1

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

Solution (Python):
K = int(input())
t = 7 % K
cnt = 1
while t != 0 and cnt < 10**6+10:
    t *= 10
    t += 7
    t %= K
    cnt += 1
if cnt == 10**6+10:
    cnt = -1
print(cnt)

Solution (Python):
def main():
    K = int(input())
    visited = [False]*K

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

        if visited[r]:
            print(-1)
            exit()
        
        visited[r] = True
    
    
if __name__ == "__main__":
    main()

Solution (Python):
import sys

step = 0
n = 0
k = int(input())
l = [0]*k
while True:
  step += 1
  n = (n * 10 + 7) % k
  l[n] += 1
  if n == 0:
    break
  elif l[n] >= 2:
    step = -1
    break
print(step)

Solution (Python):

import math

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

Solution (Python):
def makedivisor(N):  
    p, upper, lower = 1, [], []
    while p * p <= N:
        if N % p == 0:
            lower.append(p)
            if p * p != N:
                upper.append(N // p)
        p += 1
    return lower + upper[::-1]


def totient(N):  
    p, phi = 2, N
    while p * p <= N:
        if N % p == 0:
            phi = phi // p * (p - 1)
        while N % p == 0:
            N //= p
        p += 1
    if N > 1:
        phi = phi // N * (N - 1)
    return phi


k = int(input()) * 9


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

cnt = totient(k)
num = makedivisor(cnt)
for i in num:
    if pow(10, i, k) == 1:
        print(i)
        break

Solution (Python):
def makedivisor(N):  
    p, upper, lower = 1, [], []
    while p * p <= N:
        if N % p == 0:
            lower.append(p)
            if p * p != N:
                upper.append(N // p)
        p += 1
    return lower + upper[::-1]


def totient(N):  
    p, phi = 2, N
    while p * p <= N:
        if N % p == 0:
            phi = phi // p * (p - 1)
        while N % p == 0:
            N //= p
        p += 1
    if N > 1:
        phi = phi // N * (N - 1)
    return phi

k = int(input()) * 9


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

cnt = totient(k)
num = makedivisor(cnt)
for i in num:
    if pow(10, i, k) == 1:
        print(i)
        break

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
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()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
    K = II()
    d = dict()
    value = 7
    ans = 0
    r = 0
    flag = False
    while not r in d:
        d[r] = True
        r = r*10+7
        r = r % K
        ans += 1
        if r == 0 :
            flag=True
            break
    if flag:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    main()

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

out=-1

if K%7==0:
    dammy = K//7
    
    for i in range(1,10**6):
        
        if pow(10,i,9*dammy)==1:
             out=i
             break

else:
    for i in range(1,10**6):
        
        if pow(10,i,9*K)==1:
            out=i
            break

print(out)

Solution (Python):
K = int(input())
 
x = []
x.append(7%K)
for i in range(1,K):
  x.append((x[i-1]*10+7)%K)

for i,n in enumerate(x):
  if n == 0:
    print(i + 1)
    exit()
print(-1)

Solution (Python):
import sys
K=int(input())
a = [7%K]
for k in range(1, K+1):
    temp = (a[k-1]*10+7)%K
    a.append(temp)
for k in range(K+1):
    if a[k]==0:
        print(k+1)
        sys.exit()
print(-1)

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


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

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

Solution (Python):
def solve():
    K = int(input())
    if K % 10 not in [1, 3, 7, 9]:
        print(-1)
        return

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

    print(-1)

solve()

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


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

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

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

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

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

Solution (Python):
k = int(input())
cnt = 0
x = []
x.append(7)
if k == 7 or k == 1:
    print(1)
else:
    for i in range(1, k+2):
        x.append((10*x[i-1] + 7)%k)
        if x[i]%(k) == 0:
            print(i+1)
            break
        else:
            cnt += 1
            if cnt == k+1:
                print(-1)
                break

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

a = [7 % K]
if a[-1] == 0:
    print(1)
    exit()

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

Solution (Python):
V = 7
K = int(input())
A = 1
f = False
for i in range(1000005):
  if V % K == 0:
    f = True
    break
  A += 1
  V *= 10
  V += 7
  V %= K
print(A if f else -1)

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

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

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

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

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

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

Solution (Python):
k = int(input())
i, a = 1, 7
a %= k
while a != 0:
    i += 1
    a = (10 * a + 7) % k
    if i > k:
        i = -1
        break

print(i)

Solution (Python):
n=int(input())
ans=0
se=set()
for i in range(1,n+1):
    ans=ans*10+7
    ans=ans%n

    if ans==0:
        print(i)
        quit()
    if ans in se:
        break
    se.add(ans)
print(-1)

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

Solution (Python):
k = int(input())
i = 1
a = 7
a = a % k
while a != 0:
  i += 1
  a = (10*a + 7) % k
  if i == 10**6:
    i = -1
    break
 
print(i)

Solution (Python):
def main(K):
    rem = 7
    for j in range(K):
        if rem % K == 0:
            return j+1
        rem = (10*rem + 7) % K 
    return -1

K = int(input())
print(main(K))

Solution (Python):
k = int(input())
i = 1
a = 7
a = a % k
while a != 0:
  i += 1
  a = (10*a + 7) % k
  if i == 10**6:
    i = -1
    break

print(i)

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

mod_even = K % 2
mod_fifth = K % 5
mod_seven = K % 7
if mod_even == 0:
  print(-1)
elif mod_fifth == 0:
  print(-1)    
else:
  kk = 0
  if mod_seven == 0:
    kk = int(9*K/7)
  else:
    kk = int(9*K)
  count = 0
  remainder = 0
  kazu = int(10)
  while(1):
    count = count + 1
    remainder = kazu % kk
    if remainder == 1:
      print(count)
      break
    else:
      kazu = int(remainder*10)

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

Solution (Python):
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
m = 7 % K
cnt = 1
d = 10 % K
while True:
    if m == 0:
        break
    cnt += 1
    m = (m+7*d)%K
    d = d*10%K
print(cnt)

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

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

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

Solution (Python):
k = int(input())
m = 7 % k 
s = set()
cnt = 1
while(1):
    if m == 0:
        print(cnt)
        break
    elif m in s:
        print(-1)
        break
    else:
        s.add(m)
    m = ((m * (10 % k)) % k + 7 % k) % k
    cnt += 1

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

k = int(input())
s = 7 % k
for i in range(1, k + 1):
	if not s:
		exit(print(i))
	s = (s + 7 * pow(10, i, k)) % k
print(-1)

Solution (Python):


k = int(input())

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

print(-1)

Solution (Python):

K = int(input())
cur = 7
for n in range(K):
    if cur % K != 0:
        cur = (cur * 10 + 7) % K
    else:
        print(n + 1)
        break
else:
    print(-1)

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

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

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

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

Solution (Python):
import sys

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

Solution (Python):
m = int(input())
p = 0
for j in range(1, m+1):
    p = (p * 10 + 7) % m
    if p == 0:
        print(j)
        exit()
print("-1")

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




l = (9*k//7) if k % 7 == 0 else 9*k

if k == 1:
    ans = 1
elif k % 2 == 0 or k % 5 == 0:
    ans = -1
else:
    v = 1
    for i in range(1, l+1):
        v = (v*10) % l
        if v == 1:
            ans = i
            break
print(ans)

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

Solution (Python):
import sys 


n = int(input())
sev = '7'
ans = 1
while ans <= 1000000:
	if int(sev) % n == 0:
		print(ans)
		exit()
	ans = ans + 1
	sev += '7'
	sev = str(int(sev) % n)
	
print(str(-1))

Solution (Python):
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
k = ni()

if k%2==0 or k%5==0:
    print(-1)
    exit()
if k%7==0:
    L=9*k//7
else:
    L=9*k
tmp=1
for i in range(1,10**6):
    tmp = tmp*10 %L
    if tmp==1:
        print(i)
        break
else:
    print(-1)

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

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

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

t = 10%mod
i = 1
while t != 1:
    i += 1
    t = t*10%mod
print(i)

Solution (Python):
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
k = ni()
a = 0
for i in range(10**6):
    a=(a+7*pow(10,i,k))%k
    if a== 0:
        print(i+1)
        break
else:
    print(-1)

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

Solution (Python):

k = int(input())
ans = -1
x = 7

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

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    K = I()

    rem = 7 % K
    ans = 0
    is_ok = True
    seen = [False] * K
    while rem != 0:
        if seen[rem]:
            is_ok = False
            break
        seen[rem] = True
        rem = rem * 10 + 7
        rem %= K
        ans += 1

    if is_ok:
        print(ans + 1)
    else:
        print(-1)

if __name__ == '__main__':
    resolve()

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

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

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

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

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

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

def main():
    k = int(input())
    tmp = 7 % k
    digits = 1
    rems = set()
    while tmp != 0:
        if tmp in rems:
            return - 1
        rems.add(tmp)
        tmp = (tmp * 10 + 7) % k
        digits += 1
    return digits


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

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

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

def calculate(k):

    res = 1

    n = 7

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

    if k % 5 == 0:
        print(-1)
        return

    while n % k > 0:
        n = n % k
        n = n * 10 + 7
        res += 1

    print(res)

calculate(K)

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

def calculate(k):

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

    if k % 5 == 0:
        print(-1)
        return

    res = 1

    m = (((10 ** res) - 1) // 9) * 7


    while m % k > 0:
        res += 1
        m = m % k
        m = m * 10 + 7

    print(res)


calculate(K)

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

p = 0
res = -1
for i in range(10 ** 6):
    p *= 10
    p += 7
    p %= K
    if p == 0:
        res = i + 1
        break

print(res)

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

rest = 7%K
cnt = 1
while rest != 0:
    rest = (rest*10+7)%K
    cnt += 1
print(cnt)

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

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

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

else:
    surplus=1
    for i in range(1,L):
        surplus=(surplus*10)%L
        if surplus==1:
            print(i)
            break

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

count = -1
n = 7
for i in range(K):
    if n % K == 0:
        count = i+1
        break
    n = int(str(n)+'7')
    n %= K
print(count)

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

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

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

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

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

i = 0
n = 0
while True:
	n = (n * 10 + 7) % K
	i += 1
	if n % K == 0:
		print(i)
		break
	if i > 1000000:
		print(-1)
		break

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

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

print(ans)

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

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

Solution (Python):
K = int(input().rstrip())
n = 1
if K%7==0:
    L = 9 * K / 7
else:
    L = 9 * K
R = 10 ** n
s = set()
if K == 1 or K == 7:
    print(1)
else:
    while R!=1:
        R = (10 * R) % L
        n += 1
        if R in s:
            print(-1)
            break
        else:
            s.add(R)
    else:
        print(n)

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

Solution (Python):


def solve():
    K = int(input())
    a = 7%K
    i = 1
    Kset = set()
    Kset.add(a)
    while a!=0:
        a = (a*10+7)%K
        i += 1
        if a in Kset:
            print(-1)
            return
        Kset.add(a)
    print(i)


if __name__ == "__main__":
    solve()

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

def calculate(k):

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

    if k % 5 == 0:
        print(-1)
        return

    res = 1

    m = (((10 ** res) - 1) // 9) * 7


    while m % k > 0:
        res += 1
        m = m % k
        m = m * 10 + 7

    print(res)


calculate(K)

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    K=I()
    if K%2==0 or K%5==0:
        print(-1)
        exit()
    a=7
    ans=1
    for i in range(1000000):
        if a%K==0:
            break
        else:
            a=(a*10+7)%K
            ans+=1
            
    print(ans)
    

main()

Solution (Python):

K = int(input())
A = 7 % K 

flag = False
for i in range(1, K+1):
  if A == 0:
    flag = True
    break
  A = (A*10 + 7) % K

if flag:
  print(i)
else:
  print(-1)

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

print(order)

Solution (Python):
num=int(input())
a=7
flag=0
for i in range(num):
    if a%num==0:
        print(i+1)
        flag=1
        break
    a=(a*10+7)%num
if flag==0:
    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)
else: 
    state = 7 
    state %= K
    cou = 1
    while True:
        if state == 0:
            print(cou)
            break
        state = state *  10 + 7
        state %= K 
        cou+= 1

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

arr = [0] * (k+1)
r = 7 % k
ans = 1

while arr[r] == 0:
    if r == 0:
        print(ans)
        exit()
    arr[r] += 1
    r = (10 * r + 7) % k
    ans += 1

print(-1)

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

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

s = '7' * len(str(K))
if int(s) < K:
    s += '7'
ans = len(s)
s = int(s)

while True:
    s = s % K
    if s == 0:
        print(ans)
        exit()
    s = s * 10 + 7
    ans += 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())
cnt = 1
mod = 7

for _ 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())
mod = K
if K == 1:
    print(1)
elif K % 2 == 0 or K % 5 == 0:
    print(-1)
elif K % 7 != 0:
    x = 10 % mod
    X = [1] * K
    S = [1] * K
    for i in range(1, K + 1):
        X[i] = (X[i - 1] * x) % mod
        S[i] = S[i - 1] + X[i]
        if S[i] % mod == 0:
            print(i + 1)
            exit()
    print(-1)
else:
    mod = K // 7
    if mod == 1:
        print(1)
    else:
        x = 10 % mod
        y = 1 % mod
        X = [y] * K
        S = [y] * K
        for i in range(1, K + 1):
            X[i] = (X[i - 1] * x) % mod
            S[i] = S[i - 1] + X[i]
            if S[i] % mod == 0:
                print(i + 1)
                exit()
        print(-1)

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

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

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

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