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



Sample input:
101


Sample output:
4

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

x = 7 % k
cnt = 1

while 10000:
    if k % 2 ==0 or k%5==0:
        print('-1')
        break
        
    if x == 0:
        print(cnt)
        break
        
    x = x*10+7
    x = x % k
    
    cnt += 1

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
K = int(input())
M = 7 % K

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

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    for i in range(1, K+1):
        a = 7*(pow(10, i, 9*K)-1)
        a %= 9*K
        if a == 0:
            return print(i)
    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    a = 7 % K
    d = 1
    for k in range(1, K+1):
        if a == 0:
            return print(k)
        d *= 10
        d %= K
        a += 7 * d
        a %= K
    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    num = 7%K
    ans = 0
    # print(num)
    for i in range(K):
        ans += 1
        if num%K == 0:
            print(ans)
            return
        num = (num*10 +7)%K

    print(-1)
    return

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin,stdout
#for _ in range(int(stdin.readline())):
n=int(stdin.readline())
#a=list(map(int,stdin.readline().split()))
dividend=7;ans=-1
for add in range(10**6+5):
    rem=dividend%n
    if rem==0:
        ans=add+1
        break
    dividend=rem*10+7
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin,stdout
#for _ in range(int(stdin.readline())):
n=int(stdin.readline())
#a=list(map(int,stdin.readline().split()))
dividend=7;ans=-1
for add in range(10**7):
    rem=dividend%n
    if rem==0:
        ans=add+1
        break
    dividend=rem*10+7
print(ans)

Submission status: Accepted

Solution code:
k=int(input())
n=7%k
s=set()
i=1
while n not in s:
  if n == 0:
    print(i)
    exit()
  s.add(n)
  n=(10*n+7) %k
  i+=1
print(-1)

Submission status: Accepted

Solution code:
k = int(input())

if k in [2, 5, 10] == 0:
    print(-1)
    exit()

n_map = {}
current = 7 % k
cnt = 1
while True:
    if current == 0:
        print(cnt)
        exit()
    if current in n_map:
        print(-1)
        exit()
    else:
        n_map[current] = True
    cnt += 1

    current = 10 % k * current + 7
    current %= k

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
if k%2==0 or k%5==0:
    print(-1)
    exit()
cnt=1
sup=1
if k%7==0:
    t = 9*k//7
else:
    t=9*k
while 1:
    sup*=10
    sup = sup%t
    if sup==1:
        print(cnt)
        exit()
    cnt+=1

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
K = int(input())

count =1
x=7 %K

if K %2 ==0 or K %5 ==0:
    count = -1
else:

    while x %K !=0:
        count +=1
        x = (x*10 +7)%K
        #print(x,end =" ")
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = 7
for i in range(1, int(3e6)):
    if s%n == 0:
        print(i)
        exit()
    s = (s*10 + 7) % n
print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        sys.exit()
    if k % 7 == 0:
        l = k * 9 // 7
    else:
        l = k * 9
    r = 1       # カウント
    p = 10 ** r
    while (p % l) != 1:
        p = (p * 10) % l
        r += 1
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding:utf-8
k = int(input())
i = 1

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

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

for j in range(1, L + 1):
    i = (10 * i) % L
    if i == 1:
        print(j)
        exit()
print(-1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    K = II()


    used = [0] * K
    q = 7
    for i in range(K):
        q %= K
        if q == 0:
            print(i+1)
            return
        if used[q]:
            print(-1)
            return
        used[q] = 1
        q = 10*q + 7


if __name__ == '__main__':
    solve()

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    if (k%2==0 or k%5==0):
        print("-1")
        return

    #7(10**i-1)が9Kで割り切れるような最小の整数iを求める。

    if k%7==0:
        L=9*k//7
    else:
        L=9*k
    i=1
    for n in range(1,L+1):
        i=(10*i)%L
        if i==1:
            print(n)
            return
    print("-1")
    return

main()

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
l = 0
s = set()
for i in range(1,9000000):
    l = (l*10+7)%k
    if l == 0:
        print(i)
        exit()
    else:
        s.add(l)
        if len(s) == i-1:
            print(-1)
            exit()
print(-1)
exit()

Submission status: Accepted

Solution code:
import os

k = int(input())
x = 7
i = 1
if k%7==0:
    l = 9*k/7
else:
    l = 9*k

if l%2==0 or l%5==0:
    print(-1)
    exit()
else:
    a = 10%l
    for i in range(1,9000001):
        if a==1:
            print(i)
            break
        a = 10*a%l

Submission status: Accepted

Solution code:
k=int(input())
if k%7==0:
    q=9*k//7
else:
    q=9*k


now=10%q
if now==1:
    print(1) ;exit()
for ans in range(2,1000000):
    now= now*10%q
    if now==1:
        print(ans)
        exit()
print(-1)

Submission status: Accepted

Solution code:
n = int(input())
ans = 1
if n % 5 == 0 or n % 2 == 0:
    print(-1)
else:
    t = 7
    while t % n != 0:
        t = t * 10 + 7
        t %= n
        ans += 1
    print(ans)

Submission status: Accepted

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

val = 7
ans=1
while(1):
    if val%K==0:
        print(ans)
        exit()
    val = (val*10+7) % K
    ans +=1

Submission status: Accepted

Solution code:
k = int(input())

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

dct = {0: 0}
for i in range(1, 10):
    dct[(lsd*i) % 10] = i

l = k
c = 0
while l > 0:
    t = l % 10
    n = dct[(7 - t) % 10]
    l += (k*n)

    l //= 10
    c += 1

print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    n = 7
    cnt = 1
    for i in range(k):
        if n % k == 0:
            break
        cnt += 1
        n = (n * 10 + 7) % k
    print(cnt)

Submission status: Accepted

Solution code:
k = int(input())

x = 7%k

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

Submission status: Accepted

Solution code:
def main():

    k = int(input())

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    print(result)

Submission status: Accepted

Solution code:
k = int(input())

if str(k)[-1] not in ["1","3","7","9"]:
    print(-1)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

t = 7 % K
if t == 0:
    print(1)
    exit()

for i in range(2, 10**6):
    t = (t * 10 + 7) % K
    if t == 0:
        print(i)
        exit()

print(-1)

Submission status: Accepted

Solution code:
K=int(input())
i=1
x=7
mod=set()
while True:
  if x%K==0:
    print(i)
    break
  else:
    if x%K in mod:
      print(-1)
      break
    mod.add(x%K)
    x=(x%K)*10+7
    i+=1

Submission status: Accepted

Solution code:
K = int(input())

flag = [0 for _ in range(K)]  # flag[i] : あまり i が登場したかどうか

if 7%K == 0:
    print(1)
else:
    now_n = 7%K
    flag[now_n] = 1
    while True:
        next_n = (now_n*10 + 7) % K
        if next_n == 0:
            print(sum(flag)+1)
            exit()
        elif flag[next_n] == 0:
            now_n = next_n
            flag[now_n] = 1
        else:
            print(-1)
            exit()

Submission status: Accepted

Solution code:
from math import log10
x = int(input())

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

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

n = 1
amari = 1
while n < 9000000:
    amari = (amari*10) % L
    if amari == 1:
        print(n)
        exit(0)
    else:
        n += 1
print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
c = 0
if k%2 ==0 or k%5==0:
    print(-1)
    c=1
elif k==1:
    print(1)
    c=1
if c==0:
    t = 7

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    l = [False] * K
    ans = 1
    now = 0
    while True:
        now = now * 10 + 7
        now %= K
        if now == 0:
            print(ans)
            break

        if l[now]:
            print(-1)
            break
        
        l[now] = True
        ans += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
K = int(input())

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

print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - Repsept
def main():
    k = int(input())
    cnt = 7
    
    for i in range(1, k+1):
        if cnt%k == 0:
            print(i)
            exit()
        cnt = (10*cnt+7) % k
    else:
        print(-1)

if __name__ ==  "__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())

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

print(-1)

Submission status: Accepted

Solution code:
K = int(input())
x = 7
ans = 1
if x%K==0:
  print(ans)
  exit()
visited = [0]*(K+1)
while x!=0:
  x %= K
  x = x*10+7
  x %= K
  if visited[x]:
    print(-1)
    exit()
  visited[x] = 1
  ans += 1
print(ans)

Submission status: Accepted

Solution code:
K = int(input())

a = 0
ans = -1
S = set()
for i in range(1, K + 1):
    a = a * 10 + 7
    a %= K
    if a == 0:
        ans = i
        break
    elif a in S:
        break
    S.add(a)
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        sys.exit()
    p = 7       # '7,77,777…'のmod kをいれる変数
    plus = 7    # '70,700,7000…'のmod kをいれる変数
    r = 1       # カウント
    while (p % k) != 0: # kで割り切れるかチェック
        plus = (plus * 10) % k   # pに足すもう1桁のmod kを計算。
        p += plus                # pにもう１桁を足す
        p = p % k                # pのmod kをとる
        r += 1
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
K = int(input())

seen = set()

extra = 7 % K
i = 1

while extra not in seen:

    if extra == 0:
        print(i)
        exit()
    
    seen.add(extra)
    extra = (extra * 10 + 7) % K
    i += 1

print(-1)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        sys.exit()
    p = 7
    plus = 7
    amari = set()
    r = 1
    while (p % k) != 0:
        if p in amari:
            print(r, -1, p)
            sys.exit()
        else:
            amari.add(p)
            plus = (plus * 10) % k
            p += plus
            p = p % k
            r += 1
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
k = int(input())

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

print(-1)

Submission status: Accepted

Solution code:
K = int(input())
rem_set = set()
rem = 7%K
i = 1
while True:
    if rem == 0:
        print(i)
        break
    if rem in rem_set:
        print(-1)
        break
    i += 1
    rem_set.add(rem)
    rem = (rem*10 + 7)%K

Submission status: Accepted

Solution code:
n=int(input())
e=len(str(n))
e1=int('7'*e)
if e1<n:
    e1=e1*10+7
tr=1
s=set()
t=e1%n
ans=len(str(e1))
while(t!=0):
    if t in s:
        tr=0
        break
    s.add(t)
    e1=t*10+7
    t=e1%n
    ans+=1
if tr==0:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
k=int(input())

mod=[0]*k
c=7
cnt=1

while True:
    if c%k==0:
        print(cnt)
        break
    
    mod[c%k]=1

    c*=10
    c+=7
    c%=k
    cnt+=1

    if mod[c]==1:
        print(-1)
        break

Submission status: Accepted

Solution code:
K = int(input())
m = 7%K
ans = 1
s = set()
s.add(m)
for _ in range(K):
    #print(m)
    if m == 0:
        print(ans)
        break
    m = (m*10+7)%K
    if m in s:
        print('-1')
        break
    else:
        s.add(m)
    ans += 1

Submission status: Accepted

Solution code:
K = int(input())
before = 0
for i in range(1, 10**6+1):
    n = before*10+7
    if n >= K and n%K == 0:
        print(i)
        exit()
    before = n%K
print(-1)

Submission status: Accepted

Solution code:
k=int(input())

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

Submission status: Accepted

Solution code:
K=int(input())
List = list(str(K))
i = len(List)
tryNum = 7*10**i
res = -1
if K % 2 == 0 or K % 5 == 0:
  print(res)
else:
  flag = True
  mid=0
  K=9*K
  N=0
  while flag:
    N = tryNum % K
    if  N == 7 :
      res = i
      flag = False
    else:
      i += 1
      tryNum= N*10
  print(res)

Submission status: Accepted

Solution code:
def main(k):
    size, res = 1, 7 % k
    while res and size <= k:
        res = (res * 10 + 7) % k
        size += 1
    return -1 if size > k else size


if __name__ == '__main__':
    k = int(input())
    print(main(k))

Submission status: Accepted

Solution code:
K = int(input())

c = 0

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

print(-1)

Submission status: Accepted

Solution code:
k = int(input())
mod = 7
#l = []

for i in range(10**6):
    j = mod % k
#    logging.debug("i = {}, mod = {}, mod % k ={}".format(i,mod,j))
    if i > 1 and j == 7:
        print(-1)
        exit()
    if j == 0:
        print(i + 1)
        exit()
    else:
        #l.append(j)
        #if len(set(l)) != len(l):
        #    print(-1)
        #    exit()
        mod = j * 10 + 7
print(-1)

Submission status: Accepted

Solution code:
def main(k):
    size, res = 1, 7 % k
    while res and size <= 1_000_000:
        res = (res * 10 + 7) % k
        size += 1
    return -1 if size > 1_000_000 else size


if __name__ == '__main__':
    k = int(input())
    print(main(k))

Submission status: Accepted

Solution code:
k = int(input())
checked = [False] * k

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
t = 7
ans=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# 整数の入力
k = int(input())

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

print(-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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

    k = int(input())
    x = 7 % k  # k == 7の場合への対処

    # KeyInsight:
    # ◯: Mod kを取る
    # ◯: 値が(x * 10 + 7)ずつ増えていく
    # △: Modを取った後の演算について理解が浅かった
    for i in range(1, k + 1):
        if x == 0:
            print(i)
            exit()

        x = (x * 10 + 7) % k

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#C

K=int(input())
ans=-1
if K==1:
    ans=1
elif K==2 or K==5 or K==10:
    ans=-1
else:
    p=0
    for i in range(1,K+1):
        p = (p*10+7)%K 
        #print(i,p)
        if p==0:
            ans=i
            break

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

c = 0

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

print(-1)

Submission status: Accepted

Solution code:
K=int(input())
N=7%K
cnt=0
ret=-1
while cnt< K:
  cnt+=1
  if (N % K) == 0:
    print (cnt)
    break
  N=(N*10+7)%K
else:
  print (-1)

Submission status: Accepted

Solution code:
from collections import defaultdict
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    K = int(input())

    if not K % 2:
        print(-1)
        return

    x = defaultdict(int)
    mod = 7 % K
    for i in range(K):
        if not mod:
            print(i + 1)
            break
        if x[mod]:
            print(-1)
            break
        x[mod] = 1
        mod = (mod * 10 + 7) % K


main()

Submission status: Accepted

Solution code:
k = int(input())
if k % 7 == 0:
    L = 9 * k // 7
else:
    L = 9 * k
out = -1
s = 10
for i in range(L):
    if s % L == 1:
        out = i + 1
        break
    else:
        s = (s % L) * 10
print(out)

Submission status: Accepted

Solution code:
k = int(input())

now = 7

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

Submission status: Accepted

Solution code:
K = int(input())
x = 7 % K

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

else: print(-1)

Submission status: Accepted

Solution code:
K = int(input())
x = 7 % K
num_list = []

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

else: print(-1)

Submission status: Accepted

Solution code:
import math
import time
start=time.time()
K=int(input())
ans=0
if K%2==0:
    print(-1)
else:
    if K%7==0:
        K//=7
    k=1
    kk=1
    while True:
        now=time.time()
        if (now-start)>1.8:
            ans=-1
            break
        kk*=10
        kk%=9*K
        if kk==1:
            ans=k
            break
        else:
            k+=1


    print(ans)

Submission status: Accepted

Solution code:
k = int(input())

def answer(k):
    if k % 2 == 0 or k % 5 == 0:
        return -1
    d = 1
    r = 7
    while r % k != 0:
        r = 10 * r + 7
        r %= k
        d += 1
    return d

print(answer(k))

Submission status: Accepted

Solution code:
###############################################
#                                             #
#   author: raghav_0901 (Raghav Dalmia)       #
#   updated on: 04-08-2020,  3:48:16 pm IST   #
#                                             #
###############################################


from math import *

k = int(input())

if(k % 2 == 0 or k % 5 == 0):
    print(-1)
else:
    ans = 1
    num = 7 % k
    while(num > 0):
        num = ((num * 10) + 7) % k
        ans = ans + 1
    print(ans)

Submission status: Accepted

Solution code:
k=int(input())

# mod k で考える
mod=k
flag=True
for i in range(1,10**6+1):
    if i<=7:
        if mod > 7 * int(str(1) * i):
            continue
        else:
            pass
    if mod == k:
        mod = 7 * int(str(1) * i) % mod
        if mod == 0:
            print(i)
            exit()
    else:
        mod = (mod * 10 + 7) % k
        if mod == 0:
            print(i)
            exit()

print(-1)

Submission status: Accepted

Solution code:

def resolve():
    K = int(input())
    val = 7
    for i in range(K):
        if val % K == 0:
            print(i+1)
            break
        val = (val*10 + 7) % K
    else:
        print(-1)

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
k=int(input())

# mod k で考える
mod=7
if mod%k==0:
     print(1)
     exit()

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

print(-1)

Submission status: Accepted

Solution code:
n=int(input());p=7%n;c=-1
for i in range(10**6):
	if p==0:c=i+1;break
	p=(p*10+7)%n
print(c)

Submission status: Accepted

Solution code:
k=int(input())

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

print(-1)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())


def solve():
    divs = set()
    r = 0
    cnt = 1
    while (r * 10 + 7) % N not in divs:
        r = (r * 10 + 7) % N
        divs.add(r)
        if r == 0:
            return cnt
        cnt += 1

    return -1


print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(N):
    if L % 2 == 0 or L % 5 == 0:
        print(-1)
        return
    else:
        before = 10 % L
        if before == 1:
            print(1)
            return
        for i in range(L):
            before = (10 * before) % L
            if before == 1:
                print(i + 2)
                return
        print("error")
        return

K = int(input())
if K % 7 == 0:
    L = 9 * K // 7
else:
    L = 9 * K
#print(L)
main(L)
#print("A")

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
K=int(input())
def x():
    count=0
    for i in range(K):
        count =(10*count+7)%K#余りからいく
        if count==0:
            return i+1
    return -1    
print(x())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
F = set()
val = 7
flg = True
for i in range(K+6):
  if val % K == 0:
    flg = False
    print(i+1)
    break
  F.add(val%K)
  val *= 10
  val += 7
  val %= K
  if val % K in F:
    break
if flg:
  print(-1)