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())
ama=[0]*(k)
now=7%k
ama[now]+=1
if now==0:
  print(1)
  exit()
for i in range(2,k+1):
  now=(10*now+7)%k
  if ama[now]!=0 and now>0:
    print(-1)
    exit()
  elif now==0:
    print(i)
    exit()
  else:
    ama[now]+=1

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

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

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

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

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

flag = 0
temp = 7
for i in range(k):
    if(temp % k == 0):
        flag = 1
        break
    else:
        temp = temp % k
        temp = temp * 10 % k
        temp = temp + 7

if (flag == 0):
    print("-1")
else:
    print(i+1)

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


if __name__ == '__main__':
    main()

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

ans = -1
num7 = 7

for i in range(1000000):
    if (num7 % K) == 0:
        ans = i+1
        break
    else:
        num7 = (num7*10+7)%K
        i+=1

print(ans)

Solution (Python):
k=int(input())
if k%2==0:
    print(-1)
else:
    n=7
    cnt=1
    l={}
    while n%k!=0:
        if n not in l:
            l[n]=1
        else:
            print(-1)
            exit()
        n=(n*10+7)%k
        cnt+=1
    print(cnt)

Solution (Python):
import math
k=int(input())
if(k%2)==0:
    print("-1")
else:
    flag=0
    for x in range(1,1000001):
        if (7%(9*k)*(pow(10,x,k*9)-1)%(9*k))==0:
            print(x)
            flag=1
            break
    if flag==0:
        print(-1)

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

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

def a(n):
    t = n * 10 + 7
    return t % k

a_i = 7
i = 1
if a_i % k == 0:
    print(i)
    sys.exit()

for j in range(k+1):
    a_i = a(a_i)
    i += 1
    if a_i % k == 0:
        print(i)
        sys.exit()
print(-1)

Solution (Python):
import sys

K = int(input())

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

x = 1
for i in range(1, 1000000):
    if (x * 7) % K == 0:
        print(i)
        sys.exit()
    x = (x + pow(10,i,K))%K

print("-1")
sys.exit()

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

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

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

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

if __name__ == '__main__':
    main()

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

def calc(target):
    result = 0
    count = 0
    if target % 2 == 0:
        print(-1)
        return
        
    for i in range(n):
        result = (result * 10 + 7) % target
        count += 1
        if result == 0:
            print(count)
            return
    
    print(-1)
    
calc(n)

Solution (Python):
import sys
k = int(input())
a = dict()
cnt = 0
base = 0
while True:
    cnt += 1
    base = (base*10+7)%k
    if base == 0:
        break
    if base in a:
        cnt = -1
        break
    else:
        a[base] = 1
print(cnt)

Solution (Python):

K = int(input())
ans = 0
rem = 0
for i in range(K):
    rem = (10*rem + 7)%K
    if rem == 0:
        print(ans+1)
        quit()
    ans += 1
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)
    quit()
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)
    quit()
print(-1)

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

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

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

a = 7
for i in range(1, k + 1):
  if a % k == 0:
    print(i)
    break
  a = (10 * a + 7) % 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):
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    k = ni()
    c = 0
    for i in range(k):
        c = (c * 10 + 7) % k
        if c == 0:
            print(i+1)
            break
    else:
        print(-1)
    return

solve()

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

def test_case(k):
    ans,cnt = 7,1
    
    if k % 2 == 0 or k % 5 == 0:
        return -1
    
    if k == 1 or k == 7:
        return 1
    
    while (1):
        ans = (ans * 10 + 7) % k
        cnt += 1
        
        if ans == 0:
            return cnt
        
print(test_case(k))

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

mods = [0] * (K+1)
mods[1] = 7 % K

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

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

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

    crawler = 7
    found = False
    i = 1

    if (K % 2 ==0) or (K % 5 == 0):
        print(-1)
    else:
        a = [0 for i in range (K+1)]
        a[0] = 7
        for i in range (1, K+1):
            a[i] = (a[i-1]*10 + 7) % K
        a[0] = a[0] % K
        for i in a:
            if i == 0:
                print(a.index(i) + 1)
                found = True
                break
        if not found:
            print(-1)
    
main()

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

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

  if curr == 0:
    print(i)
    exit()
print(-1)

Solution (Python):


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

Solution (Python):

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

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

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

Solution (Python):
def solve(K):
    K_one = K % 10
    cnt = 0

    carry = 0
    carry_one = carry % 10

    while True:
        is_ok = False
        for i in range(0,9+1):
            if (i * K_one + carry_one) % 10 == 7:
                is_ok = True
                cnt += 1
                carry = (K * i + carry) // 10
                carry_one = carry % 10
                break
        
        if not is_ok:
            print(-1)
            return
        
        if carry == 0:
            print(cnt)
            return

        carry_str = str(carry)
        if carry_str.count('7') == len(carry_str):
            print(len(carry_str) + cnt)
            return
    
if __name__ == '__main__':
    K = int(input())
    solve(K)

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

    check_list = set()
    check = 7 % K
    res = 1
    while check % K != 0:
        check = 10*check + 7
        check %= K
        res += 1
        if check not in check_list:
            check_list.add(check)
        else:
            print(-1)
            exit()
    print(res)

if __name__ == "__main__":
    main()

Solution (Python):
def calc(K):
    if K % 2 == 0:
        print(-1)
        return
    elif 7 % K == 0:
        print(1)
        return

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

    print(-1)


K = int(input())

calc(K)

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

a = [0] * 1000001
a[0] = 7 % K
for i in range(1000000):
    a[i+1] = (a[i] * 10 + 7) % K 
    
    if (a[i] == 0):
        break

if(i == 999999):
    print('-1')
else:
    print(i+1)

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

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

print(ans)

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

a = []
cnt = 0


a.append(7 % K)

for i in range(K):
    
    a.append((a[i]*10 + 7) % K)

for j in range(K):
    if a[j] == 0:
        cnt = 1
        break

if cnt == 0:
    print('-1')
else:
    print(j+1)

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

Solution (Python):
K = int(input())
N=7
A = 1


def f(A, L):
    if L % 2 == 0 or L % 5 == 0:
        A = -1
    else:
        x = 10
        b = 0
        while b == 0:
            if x % L == 1:
                break
            else:
                x = (x * 10) % L
                A += 1
    return A


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

print(A)

Solution (Python):
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print(-1)
else:
  if k % 7 == 0:
    k /= 7
  m = 1
  m2 = 1
  c = 1
  while m % k != 0:
    m2 = (m2*10)%k
    m = (m+m2)%k
    c += 1
  print(c)

Solution (Python):
K = int(input())
ans = 1
dp = [-1] * K
num = 7
while True:
    num = num % K
    if dp[num % K] != -1:
        print(-1)
        break
    elif num % K == 0:
        print(ans)
        break
    else:
        dp[num % K] = 1
    ans += 1
    num = num * 10 + 7

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()


if n % 7 == 0:
    n //= 7
    n *= 9
    if n % 2 and n % 5:
        co = 1
        i = 0
        while True:
            i += 1
            co *= 10
            co %= n
            if co == 1:
                break
        print(i)
    else:
        print(-1)
else:
    n *= 9
    if n % 2 and n % 5:
        co = 1
        i = 0
        while True:
            i += 1
            co *= 10
            co %= n
            if co == 1:
                break
        print(i)


    else:
        print(-1)

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


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


def solve():
    K = input()

    ans = len(K)
    K = int(K)
    x = int("7" * ans)

    use = set()
    while 1:
        if x % K == 0:
            break
        x = (x % K) * 10 + 7

        if x in use:
            print(-1)
            return 
        use.add(x)
        ans += 1

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

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

Solution (Python):
def main():
    k = int(input())
    A = [0 for i in range(k)]
    m = 7%k
    M = 7%k
    cnt = 1
    while  True:
        if A[m] != 0:
            print(-1)
            return
        else:
            if m==0:
                print(cnt)
                return
            else:
                cnt += 1
                A[m] = 1
                M = M*10 % k
                m = (M+m) % k

if __name__ == "__main__":
    main()

Solution (Python):





K = int(input())
















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

print(i + 1)

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

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

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

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

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

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

Solution (Python):
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    buf = {}
    K = iRaw()
    tmp = 7%K
    buf[tmp]=1
    idx = 1
    while True:
        if tmp == 0:
            print(idx)
            return
        idx+=1
        tmp = (tmp*10+7)%K
        if tmp in buf:
            print(-1)
            return
        buf[tmp]=1

main()

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

cnt = 0
a = 0
ans = False

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

if ans == False:
    print(-1)

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

Solution (Python):


import sys
input = sys.stdin.readline
from bisect import bisect_left;
from bisect import bisect_right;
from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1;
    return x;
    

def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;


def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);


def nCr(n, k): 
    if(k > n - k): 
        k = n - k; 
    res = 1;
    for i in range(k): 
        res = res * (n - i);
        res = res / (i + 1); 
    return int(res);


def primefs(n):
    
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    
    
    return primes


def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 


def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;









def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;




def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x


def sieve(n): 
    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
    return prime


MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    




def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret;
    
    


def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));


def str_array():
    return input().strip().split();


MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');




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

Solution (Python):


import sys
input = sys.stdin.readline
from bisect import bisect_left;
from bisect import bisect_right;
from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1;
    return x;
    

def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;


def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);


def nCr(n, k): 
    if(k > n - k): 
        k = n - k; 
    res = 1;
    for i in range(k): 
        res = res * (n - i);
        res = res / (i + 1); 
    return int(res);


def primefs(n):
    
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    
    
    return primes


def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 


def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;









def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;




def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x


def sieve(n): 
    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
    return prime


MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    




def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret;
    
    


def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));


def str_array():
    return input().strip().split();


MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');




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

Solution (Python):
from itertools import *
from math import gcd

k = int(input())
if gcd(k, 10) == 1:
    i = 0
    r = 0
    while True:
        i += 1
        r = (10*r+7)%k
        if r == 0:
            print(i)
            break
else:
    print(-1)

Solution (Python):
import sys
import  math
import fractions
from collections import defaultdict
import copy
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

K=int(input())
mod_l=[0]*(K*10)
mod_l[0]=7%K
mod_k=7%K
ans=1
for i in range(10*K-1):
    if(mod_l[i]==0):
        print(ans)
        sys.exit(0)
    mod_k=(mod_k*10)%K  
    if(mod_k==0):
        print("-1")
        sys.exit(0)
    mod_l[i+1]=(mod_l[i]+mod_k)%K
    ans+=1

print("-1")

Solution (Python):
K=int(input())
a=-1
b=0

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

print(a)

Solution (Python):


K = int(input())
MAX = 1000001
a = []
a.append(7 % K)
for i in range(1,K):
    a.append((a[i-1] * 10 + 7) % K)

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

print(-1)

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

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

ans=1
num=7%k

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

print(ans)

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

isCorrect = False
for i in range(K):
  if a[i] == 0:
    print(i+1)
    isCorrect = True
    break
if not isCorrect:
  print("-1")

Solution (Python):
K = eval(input())
myNumber = 0

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

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

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

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

Solution (Python):
def main():
    k = int(input())
    amari = 7
    ans = 0

    while ans <= k:
        amari = amari % k
        ans += 1
        if amari == 0:
            print(ans)
            exit()
        else:
            amari = amari * 10 + 7
            
    print(-1)


if __name__ == "__main__":
    main()

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

N = 0
count = -1

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

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

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

Solution (Python):
import sys

k=int(input())
mae=0

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

print(-1)

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

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

Solution (Python):





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

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

if K%2==0:
    print('-1')
else:
    t=True
    n=1
    a=7
    
    while t:
        if n>K:
            t=False
            print('-1')
        if a%K!=0:
            a=(10*a+7)%K
            n+=1
        else:
            t=False
            print(n)

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

for _ in range(K):
    s=(10*s+7)%K
    if s==0:
        print(_+1)
        exit()
        
print(-1)

Solution (Python):
K = int(input())
mod = 0
Good = True
for k in range(K):
    mod = (mod * 10 + 7) % K
    if mod == 0:
        print(k+1)
        Good = False
        break
if Good:
    print(-1)

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

a=7 
b=10
i=0 

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

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

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

k = int(input())

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

if k == 7:
    print(1)
    exit()

if k == 1:
    print(1)
    exit()

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

seven = 7
d = 1
while seven != 0:
    seven += pow(7*pow(10,d,k),1,k)
    seven = pow(seven,1,k)
    d += 1

print(d)

Solution (Python):
import itertools

k = int(input())

mod = set()
seven = 7 % k

for i in itertools.count():
  if seven == 0:
    print(i+1)
    break;
  elif seven in mod:
    print(-1)
    break;
  mod.add(seven)
  seven = (seven*10+7) % k

Solution (Python):
limit = pow(10, 7)
K = int(input())
num = "7"
if K % 2 == 0 or K % 5 == 0:
    print (-1)
else:
    total = 0
    flag = False
    for i in range(1, limit + 1):
        total = (total * 10 + 7) % K
        if total == 0:
            flag = True
            break
    if flag:
        print (i)
    else:
        print(-1)

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

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

print(-1)

Solution (Python):
res = 7
cnt = 1
k = int(input().rstrip())
res_list = [0 for _ in range(k)]
flg = 0
while True:
  res %= k
  if res == 0:
    flg = 1
    break
  if res_list[res] == 1:
    break
  res_list[res] = 1
  cnt += 1
  res = res * 10 + 7
if flg == 1:
  print(cnt)
else:
  print(-1)

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

if K%2 ==0 or K%5 == 0:
    ans = -1
else:
    det = 0
    num = 0
    cur = 0
    while True:
        num += 1
        cur += 7*pow(10,num-1,K)
        cur %= K
        
        
        if cur == 0:
            ans = num
            break

print(ans)

Solution (Python):
k = int(input())
a = [None]*1000001
a[1]=7%k
n=0

if a[1]==0:
    print("1")
    n=1

for i in range(2,k+1):
    a[i]=(a[i-1]*10+7)%k
    if a[i]==0 and n==0:
        print("{}".format(i))
        n=1
if n==0:
    print("-1")

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

Solution (Python):
k = int(input())
dic = dict()
cnt = 1
num1 = 7 % k
num2 = 70 % k
while True:
    if dic.get(num1):break
    if (num1) == 0:
        print(cnt)
        exit()
    
    dic[num1] = 1
    num1 = (num1 + num2) %k
    num2 = (num2 * 10) %k
    cnt += 1
    
print(-1)

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

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 = 7
    
    
    
    while True:
        amari = term % K
        if amari == 0:
            print(i)
            exit(0)
        term = amari * 10 + 7
        i += 1

if __name__ == '__main__':
    main()