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())
r = 7 % K
ans = -2
for i in range(K):
   if r == 0:
      ans = i
      break
   r = 10*r + 7
   r = r % K
print(ans+1)

Submission status: Accepted

Solution code:
K = int(input())

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

print("-1")

Submission status: Accepted

Solution code:
import sys
import numpy as np  # noqa
import numba  # noqa
from numba import njit, b1, i4, i8, f8  # noqa

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


@njit((i8, ), cache=True)
def main(K):
    for i in range(K):
        if i == 0:
            a = 7 % K
        else:
            a = (a * 10 + 7) % K
        if a == 0:
            return i + 1

    return -1


K = int(readline())

print(main(K))

Submission status: Accepted

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

x = 7
for ans in range(1, K*2):

    if  x%K == 0:
        print(ans)
        sys.exit()

    x = (x*10 + 7) % K
print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:

K=int(input())
a_i=7%K
i=1
if a_i==0:
	exit(print(1))
while True:
	i+=1
	a_i=(10*a_i+7)%K
	if a_i==0:
		print(i)
		exit()
	if i>=K:
		print(-1)
		exit()

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
str = input()
num = int(str)
if num % 2 == 0:
  print('-1');
else:
  i = 1
  j = 7
  while j % num != 0 and i <= num:
    j = (j % num) * 10 + 7
    i += 1
  if i > num:
    print('-1');
  else:
    print(i);

Submission status: Accepted

Solution code:
k=int(input())
cnt=1
mod=7

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:
import sys
sys.setrecursionlimit(10**8)

K = int(input())

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

Submission status: Accepted

Solution code:
k = int(input())

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

print(-1)

Submission status: Accepted

Solution code:
K = int(input())
seven_number = 0
ality = 0
for ans in range(1,10**7):
        if ans > K:
            print("-1")
            break
        else:
            seven_number = (seven_number*10+7) % K
            if seven_number ==0:
                print(ans)
                break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

k = I()
n = 0
c = 0

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

print(-1)
exit()

Submission status: Accepted

Solution code:
k = int(input())

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

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

Submission status: Accepted

Solution code:
import sys
def main():
    k = int(input())

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

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

    print(-1)
    
main()

Submission status: Accepted

Solution code:
import sys

k = int(input())

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

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

Submission status: Accepted

Solution code:
# abc174_c.py
# https://atcoder.jp/contests/abc174/tasks/abc174_c


# [開発時用] ログ関数
def lg(value):
    flag = False
    flag = True
    if flag:
        print(str(value))


# [開発時用] exit処理
def xt(log):
    lg('★exit() - ' + str(log))
    exit()


# 本体
def get_results():

    # 引数処理部
    lines = list()
    # 仕様でn行と決まっている場合(の例)
    lines_count = 1
    # 先頭行のNで行数が決まる場合(の例)
    # line = input()
    # lines.append(line)
    # N = int(line)
    # lines_count = N
    for _ in range(lines_count):
        lines.append(input())

    # 演算部
    # S = lines[0]
    K = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[0].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = 0

    tmp = 7

    if K % 5 == 0 or K % 2 == 0:
        return [-1]

    for k in range(K):

        q, mod = divmod(tmp, K)
        if mod == 0:
            return [k+1]
        tmp = mod * 10 + 7


# 主処理
def main():
    results = get_results()

    for result in results:
        print(result)


# 起動処理
if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
x = int(input())
cnt = 1
mod = 7

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
count = 1
mod = 7
answer = -1

for _ in range(K):
    if mod % K == 0:
        answer = count
        break
    count += 1
    mod = (mod * 10 + 7) % K

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

num = 0
cnt = 0
ans = -1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
Ans = -1

if K % 2 == 0 or K % 5 == 0:
#解なしのため何もしない
  pass
  
elif 7 % K == 0:
  Ans = 1
  
else:
  pre_modK = 7 % K
  for i in range(2,K+1):
    modK = pre_modK * 10 + 7
    if modK % K == 0:
      Ans = i
      break
    else:
      pre_modK = modK % K

print(Ans)

Submission status: Accepted

Solution code:
Kin = int(input())

i = 0
now = 0

if (0 == (Kin % 2)) or (0 == (Kin % 5)):
    print(-1)
else:
    while 1:
        now = (now * 10 + 7) % Kin
        i+=1

        if now == 0:
            break
    print(i)

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k = ni()

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

Submission status: Accepted

Solution code:
import sys

k = int(input())

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

if ans[0] == 0:
    print(1)
    
else:
    for i in range(k):
        ans[i+1] = (ans[i]*10 + 7) % k
        
        if ans[i+1] == 0:
            print(i+2)
            sys.exit()
            
    print(-1)

Submission status: Accepted

Solution code:
def main2():
    K = int(input())

    rem = set()
    n = ans = 0

    while True:
        n = n * 10 + 7
        ans += 1

        if n % K == 0:
            print(ans)
            break
        else:
            n = n % K
            
            if n in rem:
                print(-1)
                break
            else:
                rem.add(n)
                
if __name__ == "__main__":
    main2()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
INF = 10**18

a = [INF] * (K+1)
a[0] = 0

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

Submission status: Accepted

Solution code:
k = int(input())

mod = 7%k
path = [mod]
ans = '-1'

for i in range(1,k+1):
    if mod == 0:
        ans = i
        break
    mod = (mod*10 + 7)%k
    path.append(mod)
    if mod == path[0]:
        ans = '-1'
        break

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
k = int(input())
ans = 0
n = 7

if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit(0)
c = 1
while True:
    if n % k == 0:
        break
    n = (n * 10 + 7) % k
    c += 1

print(c)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = -1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
N = 10**6
a = [0] * N

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

Submission status: Accepted

Solution code:
K = int(input())

A = [0]*1000001
A[0] = 7%K
ans = -1

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

for i in range(1000001):
    if A[i]==0:
        ans = i+1
        break
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
dic = {}
x = 0
count = 0
while 1:
    x = (x * 10 + 7) % K
    count += 1
    if x == 0:
        print(count)
        exit()
    if x in dic:
        print(-1)
        exit()
    dic[x] = 1

Submission status: Accepted

Solution code:
K = int(input())
n = 7
c = 0
while c <= K:
  n %= K
  c += 1
  if n == 0:
    print(c)
    exit()
  n = n * 10 + 7
print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

cnt=1
Num=7%K
while cnt<=K:
  if K%2==0:
    print('-1')
    break
  if Num%K==0:
    print(cnt)
    break
  else:
    Num = (10*Num + 7)%K
    cnt+=1
else:
  print('-1')

Submission status: Accepted

Solution code:
import sys
K=int(input())
if K%2==0 or K%5==0:
    print('-1')
    sys.exit()
i=1
K=9*K
ans=10-K

while(1):
    if 7*(ans-1)%K==0:
        print(i)
        sys.exit()
    i+=1
    ans=ans*10%K

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

now = 7
cnt = 1
used = [False] * k
ten = 10
while not used[now % k]:
    if now % k == 0:
        print(cnt)
        exit()
    used[now % k] = True
    now = (now + ten * 7) % k
    ten = ten * 10 % k
    cnt += 1
print(-1)

Submission status: Accepted

Solution code:
K = int(input())
if K%2==0:
    print(-1)
elif K==1:
    print(1)
elif K==7:
    print(1)
else:
    if K%7==0:
        K = K//7
    a = 1
    cnt = 1
    ind = -1
    for i in range(K):
        a = (a*10)%K
        cnt += a
        if cnt%K==0:
            ind = i
            break
    if ind<0:
        print(-1)
    else:
        print(ind+2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
def solve(K):
    cur = 0
    tens = 1
    for i in range(1_000_001):
        cur += 7 * tens
        cur %= K
        if cur == 0:
            return i + 1
        tens *= 10
        tens %= K
    else:
        return -1


print(solve(int(input())))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
i, ai = 0, 0
while True:
    ai = (ai * 10 + 7) % K
    i += 1
    if ai == 0:
      break
print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

k = int(input())

a = 0

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

Submission status: Accepted

Solution code:
k = int(input())

ok = False
for i in range(1, k+1):
   if i == 1:
      a = 7 % k
   else:
      anext = (a * 10 + 7) % k
      a = anext
   if a == 0:
      print(i)
      ok = True
      break

if not ok:
   print(-1)

Submission status: Accepted

Solution code:
import sys

k = int(input())

a = 0

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

print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
def check7s(k):
    x = 7 % k
    for i in range(1, k + 1):
        if x == 0: return i

        x = (x * 10 + 7) % k
 
    return -1

K = int(input())
print(check7s(K))

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(K: int):
    cur = 0
    for i in range(K):
        cur += pow(10, i, K) * 7
        cur %= K
        if cur == 0:
            print(i + 1)
            return i + 1
    ret = -1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())
if k&1==0 or k%5==0:
  print(-1)
  exit()
elif 7%k==0:
  print(1)
  exit()
m=7
a=b=1
while(m>0):
  a=a*10%k
  m=(m+7*a)%k
  b+=1
print(b)

Submission status: Accepted

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

Submission status: Accepted

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

    print(-1)

resolve()

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
import sys
K=input()
if int(K)%2==0:
    print(-1)
    sys.exit()

S=int('7'*(len(K)))
ans=len(K)
K=int(K)
for i in range(10**6):
    if S%K==0:
        print(ans)
        break
    else:
        S=(S*10)%K+7
        ans+=1
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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