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

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

Submission status: Accepted

Solution code:

K = int(input())

now = 0
dic = {}

import sys
cnt = 1
while True:

    now = (now * 10 + 7) % K
    if now == 0:
        print (cnt)
        sys.exit()
    elif now in dic:
        print (-1)
        sys.exit()
    else:
        dic[now] = 1
    cnt += 1

Submission status: Accepted

Solution code:
K = int(input())

cur = 7 % K
index = 1
for _ in range(2 * 10 ** 6):
    if cur == 0:
        break
    index += 1
    cur *= 10
    cur += 7
    cur %= K

if index > 10 ** 6 + 20:
    print(-1)
else:
    print(index)

Submission status: Accepted

Solution code:
def solve() :
    k = int(input())
    n = 1
    found = set()
    v = 7
    while v % k != 0: 
        if v in found :
            return -1
        found.add(v)
        v = ((v%k) * 10+7) % k
        n += 1
    return n


print(solve())

Submission status: Accepted

Solution code:
K = int(input())
X = 7
for i in range(1, 10 ** 6 + 1):
    if not X % K:
        print(i)
        exit()
    X = (X + 7 * pow(10, i, K)) % K
print(-1)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    k = getN()
    al = {(7 % k): 1}
    mo = 7
    for i in range(k + 1):
        if mo % k == 0:
            print(i + 1)
            return
        mo = mo * 10 + 7
        mo %= k
        # print(mo, al)
        if mo in al:
            print(-1)
            return
        al[mo] = 1


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

Solution code:
import sys
k=int(input())
if k%2==0 or k%5==0:
  print(-1)
  sys.exit()
current=0
for i in range(k):
  current=(current*10+7)%k
  if current==0:
    print(i+1)
    sys.exit()

Submission status: Accepted

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

Submission status: Accepted

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

K = int(input())

amari = set()
count = 1

r = 7%K

while r>0 and r not in amari:
  amari.add(r)
  r = (10*r+7)%K
  count += 1

if r==0:
  print(count)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

Amari = [False] * K
cur = 7%K
ans = -1
for i in range(10**6 + 100):
    if cur == 0:
        ans = i+1
        break
    else:
        cur *= 10
        cur += 7
        cur %= K
print(ans)

Submission status: Accepted

Solution code:
d = int(input())
now = 0
for cnt in range(2*10**6):
  now *= 10
  now += 7
  now %= d
  if now == 0:
    print(cnt+1)
    break
else:
  print(-1)

Submission status: Accepted

Solution code:
import math
k=int(input())
if math.gcd(10,k)!=1:
    print(-1)
else:
    for i in range(1,10**6+1):
        if 7*(pow(10,i,9*k)-1)%(9*k)==0:
            print(i)
            break

Submission status: Accepted

Solution code:
MOD = int(input())
ans = 0

tmp = 1
for i in range(100000000):
    ans = (ans + tmp * 7) % MOD
    if ans == 0:
        print(i + 1)
        break
    tmp *= 10
    tmp %= MOD
else:
    print(-1)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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():
    d = dict()
    k = ni()
    c = 7 % k
    x = d[c] = 1
    while True:
        c = (c * 10 + 7) % k
        if c in d:
            break
        x += 1
        d[c] = x
    print(d.get(0, -1))
    return

solve()

Submission status: Accepted

Solution code:
k = int(input())

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

print(-1)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
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 LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

k=II()
seven=7%k
fin=set([seven])
for i in range(10**6):
    if seven==0:
        print(i+1)
        break
    seven=(seven*10+7)%k
    if seven in fin:
        print(-1)
        break
    fin.add(seven)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

K = int(input())
i = 1
v = 7 % K
V = {v}
while v != 0:
	i += 1
	v = (10 * v + 7) % K
	if v in V:
		print(-1)
		break
	V.add(v)
else:
	print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

print(main())

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

k, = [int(i) for i in read().split()]


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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
K = int(input())

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

print(digit)

Submission status: Accepted

Solution code:
k = int(input())
num = 7
count = 1
while count <= 10 ** 6:
    if num % k == 0:
        print(count)
        break
    else:
        num %= k
        num = num * 10 + 7
        count += 1
else:
    print(-1)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = [0] * n
i = 7%n
import sys
if i==0:
    print(1)
    sys.exit()

ans = 1
while A[i] == 0:
    A[i] = 1
    i = (i*10+7)%n
    ans += 1
    if i == 0:
        print(ans)
        sys.exit()

print(-1)

Submission status: Accepted

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

print(-1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    K = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    cur=7%K
    cnt=1
    for _ in range(K+1):
        if cur==0:
            print(cnt)
            return
        cur*=10
        cur+=7
        cur%=K
        cnt+=1
    print(-1)




if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
#N, M = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]
#S = input()
#S = [input() for _ in range(N)]

answer = 0
rest = 0
for i in range(2 * 10 ** 6):
    rest *= 10
    rest += 7
    rest %= N
    answer += 1
    if rest == 0:
        print(answer)
        exit()
print(-1)

Submission status: Accepted

Solution code:
k = int(input())
seen = [False]*k
now = 0
cnt = 0
while True:
    cnt += 1
    now = now*10+7
    now %= k
    if now == 0:
        break
    if seen[now]:
        print(-1)
        exit()
    seen[now] = True
print(cnt)

Submission status: Accepted

Solution code:
K = int(input())

rem = 0
k = 0
while True:
    rem += (pow(10, k, K) * 7)
    rem %= K
    if rem == 0:
        print(k + 1)
        break
    k += 1
    if k == 1000001:
        print(-1)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    k = int(ipt())
    al = [False]*k
    nk = 7
    for i in range(1,k+1):
        nk %= k
        if nk == 0:
            print(i)
            exit()
        else:
            if al[nk]:
                print(-1)
                exit()
            else:
                al[nk] = True
        nk = (nk*10+7)%k

    return None

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


k = int(sys.stdin.buffer.readline())

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

Submission status: Accepted

Solution code:
k=int(input())
r=7
for i in range(k):
    if r%k:r=(10*r+7)%k
    else:print(i+1);exit()
print(-1)

Submission status: Accepted

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

Submission status: Runtime Error

Solution code:
x = int(input())

sevens = [7*pow(10,i,x) for i in range(x)]

for i in range(x-1):
    sevens[i + 1] = (sevens[i] + sevens[i + 1]) % x
    
if x % 2 == 0:
    print(-1)
else:
    print(sevens.index(0)+1)

Submission status: Runtime Error

Solution code:
K = int(input())

powlis = [pow(10, i, K) for i in range(K)]
for i in range(K-1):
    powlis[i+1] = (powlis[i] + powlis[i+1]) % K
    
print(lis[0:10])
if 0 in lis:
    print(lis.index(0)+1)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
K = int(input())

i = 7%K
se = set(i)
cnt = 1
while True:
  if i == 0:
    print(cnt)
    break
  cnt += 1
  i = (i*10 + 7)%K
  if i in se:
    print(-1)
    break
  else:
    se.add(i)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
#from collections import defaultdict
from numba import njit
import numpy as np
def main():
    @njit()
    def s(k):
        rems = np.zeros(k)
        n = 7
        next_digit = 70
        r = 1
        while True:
            rem = n % k
            if rem == 0:
                break
            elif rems[rem]:
                r = -1
                break
            else:
                rems[rem] = 1
                n += next_digit
                next_digit *= 10
                r += 1
        return r
    k = int(input())
    if k % 2 == 0:
        print(-1)
    else:
        print(s(k))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
k = int(input())

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

else:
	cnt = len(str(k)) - 1
	sev = int('1'*cnt) * 7
	while True:
		cnt += 1
		sev += 7 * (10**(cnt-1))
		if sev % k == 0:
			break
	print(cnt)

Submission status: Runtime Error

Solution code:
import sys
from collections import deque
imput = sys.stdin.readline

n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

aa = [0]
bb = [0]

for i in range(n):
    aa.append(aa[i] + a[i])
    
for i in range(m):
    bb.append(bb[i] + b[i])
    
ans = 0

for i in range(n+1):
    time = k - aa[i]
    if time < 0:
      continue
    cnt = i
    for j in range(m+1):
        if time < bb[j]:
          cnt += j - 1
          break
        elif j == m:
          cnt += m
          break
    if ans < cnt:
        ans = cnt
        
print(ans)

Submission status: Runtime Error

Solution code:
K = int(input())
L = 0
if K % 7 == 0:
  L = 9*K//L
else:
  L = 9*K
  
t = 1
ans = -1
for i in range(1,L,1):
  t = t*10
  if t % L == 1:
    ans = i
    break
  t = t % L
print(ans)

Submission status: Runtime Error

Solution code:
K = int(input())
L = 0
if K % 7 == 0:
  L = 9*K//L
else:
  L = 9*K
  
t = 1
ans = 0
for i in range(1,L,1):
  t = t*10
  if t % L == 1:
    ans = i
    break
  t = t % L
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
num=0
if (N%2==0)or(N%5==0):
    print(-1)
else:
    for i in range(1,N):
        num+=i*7
        if num%N==0:
            break
    print(i)

Submission status: Runtime Error

Solution code:
k = int(input())
x = 7
ans = 1
if k%2 == 0 or k%5 ==0:
  ans = -1
elif 7%k == 0:
  ans = 1
else:
  for i in range(k)
    ans +=1
    x = x*10+7
    if x%k == 0:
      break


print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

a = [0]*k
a[0] = 7
cnt = 0

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

print(a.index(0) + 1 if k % 2 != 0 else -1 )

Submission status: Runtime Error

Solution code:
k=int(input())

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

Submission status: Runtime Error

Solution code:
K=int(input())
i=0
if K%2==0 or K%5==0:
  print(-1)
else:
  while i<1000001:
    if ((7*((10**(i+1))-1))/9) % K==0:
      print(i+1)
      break
    else:
      i+=1

Submission status: Runtime Error

Solution code:
K = int(input())

if K % 2 == 0　or K % 5 == 0:
  print(-1)
else:
  if K % 7 == 0:
    L = 9 * K // 7
  else:
    L = 9 * K
  a = 10 % L
  check = False
  for i in range(L):
    a %= L
    if a == 1:
      print(i + 1)
      check = True
      break
    a *= 10
  if not check:
    print(-1)

Submission status: Runtime Error

Solution code:
x= int(input())
if x%7==0:
    x=x/7
i=(len(str(x))-1)
k=9*x
if x%2==0 or x%5==0 :
    print(-1)
else:
    while True:
        if (10**i -1)%(k) ==0:
            break
        else:
            i+=1
    print(i)

Submission status: Runtime Error

Solution code:
x= int(input())
if x%2!=0 or x%5!=0 :
    print(-1)
i=1
else:
  while True:
    if (10**i -1)%(9*x) ==0:
      break
    else:
      i+=1
  print(i)

Submission status: Runtime Error

Solution code:
#C
# 7,77,777･･･=7*(1,11,111･･･)
# 7*(10^i)=7*(10^i-1)/10-1 = 7*(10^i-1)/9 がkで割れる
# 10^iを(9k,7の倍数だったら9k/7)で割ってあまりが１だったら良い
import sys
k=int(input())
if k%7==0:
    k/=7
k*=9
a=10%k
for i in range(k):
    a=a%k
    if a==1:
        print(i+1)
        sys.exit()
    a*=10
print(-1)

Submission status: Runtime Error

Solution code:
#C
# 7,77,777･･･=7*(1,11,111･･･)
# 7*(10^i)=7*(10^i-1)/10-1 = 7*(10^i-1)/9 がkで割れる
# 10^iを(9k,7の倍数だったら9k/7)で割ってあまりが１だったら良い
import sys
k=int(input())
if k%7==0:
    k/=7
k*=9
a=10%k
for i in range(k*9):
    a=a%k
    if a==1:
        print(i+1)
        sys.exit()
    a*=10
print(-1)

Submission status: Runtime Error

Solution code:
K = int(input())
a = [0] * 1000000000
a[1] = 7 % K
for i in range(2,K):
    a[i] = (a[i-1]*10 + 7) % K
for i in range(1,K):
    if a[i] == 0:
        print(i)
        exit()
print("-1")

Submission status: Runtime Error

Solution code:
K = int(input())

sevens = 7
count = 0

while(sevens % K !=0):
  count += 1
  sevens = sevens * 10 + 7
  if count > K:
    print(-1)
	break
    
print(count)

Submission status: Runtime Error

Solution code:
K = int(input())
i = 1
j = 7

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
K = int(input())
N = 0
for i in range 2000000:
    if((K // (N + (10**i)*7)) == 0):
        print(i + 1)
        sys.exit()
    else:
        N = (N + (10**i)*7)
print(-1)

Submission status: Runtime Error

Solution code:
K = int(input())
S = ''
if K % 2 == 0:
  print(-1)
else:
  cnt = 0
  while 1:
    S += '7'
    cnt += 1
  	if eval(S) % K == 0:
      print(cnt)
      break

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K = int(input())
mod = []
a[0] = 7%K
if a[0] == 0:
    print(a[0])
    exit()
for i in range(1,K+1):
    a[i] = (a[i-1]*10 + 7)%K
    if a[i] == 0:
        print("%d",a[i])
        break

else:
    print(-1)

Submission status: Runtime Error

Solution code:
K = int(input())
mod = []
a[0] = 7%K
if a[0] == 0:
    print(a[0])
    exit()
for i in range(1,K):
    a[i] = (a[i-1]*10 + 7)%K
    if a[i] == 0:
        print("%d",a[i])
        break

else:
    print(-1)

Submission status: Runtime Error

Solution code:
K = int(input())
mod = []
a[0] = 7%K
for i in range(1,K):
    a[i] = (a[i-1]*10 + 7)%K

for i in range(K):
    if a[i] == 0:
        print("%d",a[i])
        break

else:
    print(-1)

Submission status: Runtime Error

Solution code:
n,d = list(map(int, input().split()))
c=0
d *= d
for i in range(n):
  x,y = list(map(int, input().split()))
  x *= x
  y *= y
  y += x
  if y <= d:
    c += 1
print(c)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 24 12:23:05 2020

@author: vivek
"""

import math
n=int(input())

seven="7"
digits=math.log10(n)
digits=math.ceil(digits)
arr=["7" for i in range(digits)]
orignal="".join(arr)
# print(orignal)
# orignal="7"
ans=digits
if n%2==0:
    print(-1)
else:
    while True:
        int_seven=int(orignal)
        if int_seven%n==0:
            print(ans)
            break
        else:
            ans+=1
            orignal+=seven

Submission status: Runtime Error

Solution code:
import math
n=int(input())
ans=1
seven="7"
digits=math.log10(n)
digits=math.ceil(digits)
arr=["7" for i in range(digits)]
orignal="".join(arr)
# print(digits)
# orignal="7"
if n%2==0:
    print(-1)
else:
    while True:
        int_seven=int(orignal)
        if int_seven%n==0:
            print(ans)
            break
        else:
            ans+=1
            orignal+=seven

Submission status: Runtime Error

Solution code:
K = int(input())
firsta = 7 % K
if firsta == 0:
    print(1)
elif firsta == 77 % K:
    print(-1)
else:
    ans = 2
    preva = 77 % K
    while preva != firsta and preva != 0:
        preva = ((preva*10)+7) % K
        ans += 1
        if preva = firsta:
            ans = -1
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k = int(input())

if k % 7 == 0:
  k /= k7

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

  print(cnt)

Submission status: Runtime Error

Solution code:
k = int(input())

if k % 7 == 0:
  k = k/7

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

  print(cnt)

Submission status: Runtime Error

Solution code:
def main(h):
  count = 1
  n = 0
  if i in range (k):
    n = (n * 10 + 7) % k  
    if n == 0:
      break 
      print(count)
      return 0
    count += 1
  print(-1)
  
if __name__ == '__main__':
	k = int(input())
    main(k)

Submission status: Runtime Error

Solution code:
k=int(input())
if k%2==0:
  print(-1)
  exit()
  
ans=1
pin=7
mod=k

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

print('-1')

Submission status: Runtime Error

Solution code:
k=int(input())
if k%2==0:
  print(-1)
  exit()
  
ans=1
pin=7
mod=k

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

print('-1')

Submission status: Runtime Error

Solution code:
#include <stdio.h>
int a[1000001];
int main(){
    int K;
    scanf("%d",&K);
    a[1]=7%K;
    for(int i=2;i<=K;i++)a[i]=(a[i-1]*10+7)%K;
 
    for(int i=1;i<=K;i++)if(a[i]==0){
        printf("%d\n",i);
        return 0;
    }
    printf("-1\n");
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
K = int(input())
 
d = pow(9, -1, K)
t = 1
for ans in range(1, K*2):
    #x = 7*(pow(10, ans, K) - 1)*d
    t = (t*10) % K
    x = 7*(t - 1)*d
    if  x%K == 0:
        print(ans)
        sys.exit()
 
print(-1)

Submission status: Runtime Error

Solution code:
import sys
K = int(input())
 
d = pow(9, -1, K)
t = 1
for ans in range(1, K):
    #x = 7*(pow(10, ans, K) - 1)*d
    t = (t*10) % K
    x = 7*(t - 1)*d
    if  x%K == 0:
        print(ans)
        sys.exit()
 
print(-1)

Submission status: Runtime Error

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

d = pow(9, -1, K)
for ans in range(1, K):
    x = 7*(pow(10, ans, K) - 1)*d
    if  x%K == 0:
        print(ans)
        sys.exit()

print(-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k=int(input())
c=0
x=0
for c in xrange(7)
  x=x+7*10**c
  if x%k==0:
    print(c+1)
    break
  if c==6:
    print(-1)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

K = int(input())
flg = -1

@lru_cache(maxsize = None)
def recur(n):
    if n == 1:
        return 7
    else:
        return (recur(n-1) * 10 + 7) % K
    
a = [recur(n) for n in range(1, K)]

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

if flg == -1:
    print(flg)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

K = int(input())
flg = -1

@lru_cache(maxsize = None)
def recur(n):
    if n == 1:
        return 7
    else:
        return recur(n-1) * 10 + 7
    
a = [recur(n) % K for n in range(1, K)]

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

if flg == -1:
    print(flg)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

K = int(input())

@lru_cache(maxsize = None)
def recur(n):
    if n == 1:
        return 7
    else:
        return recur(n-1) * 10 + 7
    
a = [recur(n) % K for n in range(1, K)]

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

print(-1)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**8)

K = int(input())

for i in [2,5]:
    if K%i==0:
        print(-1)
        exit()

def f(i,t,K):
    t2 = (t*10+7)%K
    if t2==0:
        print(i)
        exit()
    else:f(i+1,t2,K)
f(1,0,K)