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: Runtime Error

Solution code:
import math
import time
import sys

sys.setrecursionlimit(5000)
def judge_debisible(K, seven_number):
    gcd_number = math.gcd(K,seven_number)
    elapsed_time = time.time() - start_time
    print(elapsed_time)
    if elapsed_time > 0.1:
        print("-1")
    elif gcd_number == 1 :
        judge_debisible(K, seven_number*10+7)
    else:
        print(len(str(seven_number)))

K = int(input())
start_time = time.time()
judge_debisible(K, 7)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K = int(input())

A = [0]*1000000
A[0] = 7%K
ans = 1
while 1==1:
    if A[ans-1]==0:
        break
        
    A[ans] = (A[ans-1]*10+A[0])%K
    ans += 1
    
    if A[ans-1] == A[0] and A[0] != 0:
        ans = -1
        break
        
print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

mod = 7%k
period = [mod]

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

print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

cnt = 0
mod = 7%k
period = [mod]

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

print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

cnt = 0
mod = 7%k
period = [mod]

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
if(n%2==0):
  print(-1)
k=7
c=1
while(True):
  if(k%n==0):
    print(cnt)
    break
  if(c>n):
    print(-1)
    break
  k=(k)*10+7
  c=c+1

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K = int(input())
a = 0
n = 0
out = -1
for _ in range(K):
  a += 7 * (10 ** n)
  if a % K == 0:
    out = n + 1
    break
return print(out)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K = int(input())

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

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

Submission status: Runtime Error

Solution code:
a=int(input())

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k = int(input())
seven = []
while  :
  seven.append()
  
for i in range(len(seven)):
  if (seven[i] % k == 0):
    print(i)
    break
  else:
    print(-1)

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

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

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



print(ans)

Submission status: Runtime Error

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

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



print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K = input()
num_1 = len(K)

number = 7
keta = 1
count = 1
for i in range(num_1):
  num = number*keta
  count += 1
  keta = keta*10+1
  print(num)

  while(1):
    num = number*keta
    if num % K ==0:
      print(count)
      break
      count += 1
      keta = keta*10+1
      if count ==100000:
        print(-1)
        break

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K = int(input())
num = K +1
i = 1
while i <= K:
  num = (10**i-1)*7/9
  if num % K == 0:
    break
  else:
    i += 1
if i = K + 1:
  return -1
else:
  return num

Submission status: Runtime Error

Solution code:
K = int(input())
num = K +1
i = 1
while i <= K:
  num = (10**i-1)*7/9
  if num % K == 0:
    break
  i += 1
if i = K + 1:
  return -1
else:
  return num

Submission status: Runtime Error

Solution code:
K = int(input())

if K%2 == 0 or K%5 ==0:
    print(-1)
    sys.exit()
    
N = 7
count = 0
i = 1

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

Submission status: Runtime Error

Solution code:
pos = 0
curr = 7
k = int(input())
while true:
  pos += 1
  if curr % k == 0:
    break
  else : 
    k *= 10
    k += 7
print(pos)

Submission status: Runtime Error

Solution code:
pos = 0
curr = 7
k = int(input())
while true:
  pos += 1
  if curr % k == 0:
    break
  else : 
    k = k*10 
    k += 7
print(pos)

Submission status: Runtime Error

Solution code:
import sys

k=int(input())

if k%2==0:
    print('-1')
else:
    def num(x):
        if x<1:
            return 7
        else:
            return num(x-1)*10+7

    for i in range(0,sys.maxsize):
        n=num(i)
        if n%k==0:
            print(i+1)
            break

Submission status: Runtime Error

Solution code:
k = int(input())
a=0
n=0
if k%2==0 and k%5==0:
  print(-1)
else:  
  for i in range (10**9):
    a+= 7*10**i
    if a%k ==0:
      print(i+1)
      break
    if i=10**8:
      print(-1)
      break

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
K=int(input())

flag=0　#Kで割れた時にflag=1となる。

a=7 #第i項
i=0 #index

if (K%2 !=　0):
    print(-1)

else:
    while(flag==0):
        if(a%k==0):
            flag==1
        i += 1
        a=10*a+7

    print(i)

Submission status: Runtime Error

Solution code:
k=int(input())
l=[]
x=7%k
if x == 0:
  print(1)
  break
for i in range(2,k+1):
  x=7%k
  num=(x*10+7)%k
  x=num
  l.append(num)
  if num==0:
    print(i)
    break
if 0 not in l:
  print(-1)

Submission status: Runtime Error

Solution code:
k=int(input())

l=[]
for i in range(1,k+1):
  x=7%k
  num=(x*10+7)%k
  x=num
  l.append(num)
  if num==0:
  	print(i)
    break
if 0 not in l:
  print(-1)

Submission status: Runtime Error

Solution code:
k=int(input())

l=[]
for i in range(1,k+1):
  x=7%k
  num=(x*10+7)%k
  x=num
  l.append(num)
  if num==0:
  	print(i)
    break
  if 0 not in l:
    print(-1)

Submission status: Runtime Error

Solution code:
K = int(input())

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

Submission status: Runtime Error

Solution code:
T=int(input())
if T%2==0 or T%5==0:
  print("-1")
elif T%7==0:
  K=T/7
else: K=T
A=int(10%K)
cnt=1
while A != 1:
  cnt+=1
  A=int((10*A)%K)
print(int(cnt))

Submission status: Runtime Error

Solution code:
import time
import math
def lcm(a,b):
    return int(a*b/math.gcd(a,b))
k = int(input())
k = lcm(k,7)
n = 7
c = 1
t1 = time.time() 
t2 = time.time()
while (t2-t1) <= 1.8:
  if k%7 == 0:
    s = str(k)
    if all(x=="7" for x in s):
      print(len(s))
      break
  k+=kk
  t2 = time.time()

if (t2-t1) > 1.8:
  print(-1)

Submission status: Runtime Error

Solution code:
import time
k = int(input())
kk = k
n = 7
c = 1
t1 = time.time() 
t2 = time.time()
if k%7 != 0:
  ww = True
while (t2-t1) <= 1.8:
  if k%7 == 0:
    s = str(k)
    if all(x=="7" for x in s):
      print(len(s))
      break
    if ww:
      kk = k
      ww = False
  k+=kk
  t2 = time.time()

if (t2-t1) > 1.8:
  print(-1)

Submission status: Runtime Error

Solution code:
k = int(input())
i = 0
try:
	while True:
      i++
      if int("7" * i) % k == 0:
      	print(i)
except:
    print(-1)

Submission status: Runtime Error

Solution code:
k = int(input())

if k % 2 == 0:
  print(-1)
elif k % 5 == 0:
  print(-1)
else:
  if k % 7 == 0:
    l = k * 9 / 7
  else:
    l = k * 9
    
  tmp = 1
  for i in range(l):
    tmp = tmp * 10 % l
    if tmp == 1:
      flg == 1
      print(i+1)
      break
  
  if flg != 1
  	print(-1)

Submission status: Runtime Error

Solution code:
k = int(input())

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

Submission status: Runtime Error

Solution code:
k = int(input())

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, D = (int(a) for a in input().split())
X2Y2 = [[int(a) ** 2 for a in input().split()] for b in range(N)]
X2, Y2 = [list(i) for i in zip(*X2Y2)]

c = 0
DD = D ** 2
for i in range(N):
    if X2[i] + Y2[i] <= DD:
        c += 1
print(c)

Submission status: Runtime Error

Solution code:
K = int(input())
S = 7

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

    if i >= K:
        print('-1')

Submission status: Runtime Error

Solution code:
K = input()
S = 7
i = 1
if (1 <= K) and (K <= (10 ** 6)):
    while True:
        if int(S) % K != 0:
            S = S * 10 + 7
            i += 1
        else:
            print(i)
            break

        if i > K:
            print('-1')
            break

Submission status: Runtime Error

Solution code:
K = input()
S = 7
i = 1
if (1 <= K) and (K <= (10 ** 6)):
    while True:
        if int(S) % K != 0:
            S = S * 10 + 7
            i += 1
        else:
            print(i)
            break

        if i > K:
            print(-1)
            break

Submission status: Runtime Error

Solution code:
param_k = int(input())

if param_k % 2 == 0:
  print(-1)
  
elif param_k %  == 0:
  print(-1)
  
else:
  n=0
  for i in range(param_k + 10):
    n = 10n + 7
    if n % 7 == 0:
      print(i+1)
      break
    if i == param_k + 10 - 1:
      print(-1)

Submission status: Runtime Error

Solution code:
user_input= input()
count=1
while user_input < (10**6):
	if user_input % (7*count):
      print(count)

Submission status: Runtime Error

Solution code:
import sys


a = int(input())

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
k = int(input())

ans = -1
memo = 7 % k

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
k = int(input())

ans = -1
memo = 7 % k

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
K = int(input())
s = "7" * (len(str(K))-1)
cnt = len(s)
if K%2==0 or str(K)[-1]=="5":
    print(-1)
    exit()
for _ in range(K):
    i = int(s)
    if i%K==0:
        print(cnt)
        exit()
    cnt += 1
    s += "7"
print(-1)

Submission status: Runtime Error

Solution code:
# coding: utf-8
from tqdm import tqdm
K = int(input())
s = "7" * (len(str(K))-1)
cnt = len(s)
if K%2==0 or str(K)[-1]=="5":
    print(-1)
    exit()
for _ in tqdm(range(K)):
    i = int(s)
    if i%K==0:
        print(cnt)
        exit()
    cnt += 1
    s += "7"
print(-1)

Submission status: Runtime Error

Solution code:
n = int(input())
seen = set()
ans = 0
res = 7%n
seen.add(res)
ans += 1
while res != 0:
	new = (res*10 + 7)%n
    if new not in seen:
		seen.add(new)
        res = new
        ans += 1
	else:
    	print(-1):
        exit()
print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

# 解説AC
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

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

Submission status: Runtime Error

Solution code:
n = input()
if n%2==0 or n%5==0:
  print(-1)
else:
  i = len(str(n))
  seven = int(i*"7")
  while seven % n != 0:
    i += 1
    seven = int(i*"7")
    if i > 100:
      break
  print(i)

Submission status: Runtime Error

Solution code:
K = int(input())

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

Submission status: Runtime Error

Solution code:
K = int(input())

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

Submission status: Runtime Error

Solution code:
k = int(input())
i = 1
a = 7
if k % 2 == 0:
  print("-1")
  return
while a % k != 0:
  i += 1
  a = 10*a + 7
  if i == 10**9+7:
    i = -1
    break

print(i)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K = int(input())
 
if K % 2 == 0:
  print("-1")
else:
  for i in range(K):
    if int("7"*i) % K == 0:
      print(i)
    else:
      print("-1")

Submission status: Runtime Error

Solution code:
K = int(input())

if K % 2 == 0:
  print("-1")
else:
  for i in range(K):
    if int("7"*i) % K == 0:
      print(i)
    else:
      print(-1)

Submission status: Runtime Error

Solution code:
K = int(input())

if K//2 == 0:
  print("-1")
else:
  for cnt in range():
    x = int("7"*cnt)
    if x//K == 0:
      print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N= int(input())
state = input()

newlist = sorted(state)
goalstate = "".join(newlist)

uni = 0
for l in range(len(goalstate)):
    if goalstate[l] == "W":
        uni = l
        break

def bfs(state,goalstate):
    cur_state = deque([state])
    cou = 0
    while cur_state:
        cur = cur_state.popleft()
        if cur == goalstate:
            return cou
            break
        new= list(cur)
        temp = 0
        for i in range(len(goalstate)):
            if new[i] == "W":
                temp = i
                break
        neow= 0
        for j in range(uni-1,len(goalstate)):
            if new[j] == "R":
                neow = j
                break
        tempstr = new.pop(temp)
        temp1str = new.pop(neow-1)
        new.insert(neow,tempstr)
        new.insert(temp,temp1str)
        nowstr = "".join(new)
        cur_state.append(nowstr)
        cou += 1


goal = bfs(state, goalstate)
print(goal)

Submission status: Runtime Error

Solution code:
from collections import deque
N= int(input())
state = input()
 
newlist = sorted(state)
goalstate = "".join(newlist)
uni = 0
for l in range(len(goalstate)):
    if goalstate[l] == "W":
        uni = l
        break
def bfs(state,goalstate):
    cur_state = deque([state])
    cou = 0
    while cur_state:
        cur = cur_state.popleft()
        if cur == goalstate:
            return cou
            break
        new= list(cur)
        temp = 0
        for i in range(len(goalstate)):
            if new[i] == "W":
                temp = i
                break
        neow= 0
        for j in range(uni-1,len(goalstate)):
            if new[j] == "R":
                neow = j
                break
        tempstr = new.pop(temp)
        temp1str = new.pop(neow-1)
        new.insert(neow,tempstr)
        new.insert(temp,temp1str)
        nowstr = "".join(new)
        cur_state.append(nowstr)
        cou += 1
 
 
goal = bfs(state, goalstate)
print(goal)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
K = int(input())

def calculate(k):

    res = 1

    n = 7

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

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

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

    print(res)

calculate(K)


K = int(input())

Submission status: Runtime Error

Solution code:
k=int(input())
i=1
if k%7==0:
    while (10**i)%(9*k/7)!=1:
        i+=1

else:
    while (10**i)%(9*k)!=1:
        i+=1



print(i)

Submission status: Runtime Error

Solution code:
K=int(input())

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

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

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

Submission status: Runtime Error

Solution code:
K=int(input())

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

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

else:
    surplus=1

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

Submission status: Runtime Error

Solution code:
K = int(input())
x = 7
count = 1

if 7%K==0:
  print("1")
  exit(0)
if 77%==0:
  print("2")
  exit(0)
if 777%==0:
  print("3")
  exit(0)
if 7777%==0:
  print("4")
  exit(0)
if 77777%==0:
  print("5")
  exit(0)
if 777777%==0:
  print("6")
  exit(0)
if 7777777%==0:
  print("7")
  exit(0)
  
print("-1")

Submission status: Runtime Error

Solution code:
K = int(input())

if 7%K==0:
  print("1")
  exit(0)
if 77%==0:
  print("2")
  exit(0)
if 777%==0:
  print("3")
  exit(0)
if 7777%==0:
  print("4")
  exit(0)
if 77777%==0:
  print("5")
  exit(0)
if 777777%==0:
  print("6")
  exit(0)
if 7777777%==0:
  print("7")
  exit(0)
  
print("-1")

Submission status: Runtime Error

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 = 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: Runtime Error

Solution code:
k = int(input())
power = 0
cnt = 1
if k == 1:
  print(1)
elif k%2 == 0 or k%5 == 0:
  print(-1)
elif k%7 == 0:
  l = 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: Runtime Error

Solution code:
input_str = input()
i = len(input_str)
K = int(input_str)

if(K % 2 == 0):
  print(-1)
else:
  for j in range(i):
  	num += 7*(10**i)
  while(True):
    if(num % K == 0):
      print(i)
      break
    num += 7*(10**i)
    i += 1

Submission status: Runtime Error

Solution code:
input_ = input()
i = len(input_)
K = int(input_)

if(K % 2 == 0):
  print(-1)
else:
  for j in range(i-1):
    num += 7*(10**i)
  while(True):
    num += 7*(10**i)
    if(num % K == 0):
      print(i+1)
      break
    i += 1

Submission status: Runtime Error

Solution code:
input_ = input()
i = len(input_)
K = int(input_)

if(K % 2 == 0):
  print(-1)
else:
  for j in range(i-1):
    num += 7*(10**i)
  while(True):
     num += 7*(10**i)
    if(num % K == 0):
      print(i+1)
      break
    i += 1

Submission status: Runtime Error

Solution code:
K = int(input())

num = 0
if(K % 2 == 0):
  print(-1)
else:
  i = 0
  while(True):
      num += 7*(10**i)
    if(num % K == 0):
      print(i)
      break
    i += 1

Submission status: Runtime Error

Solution code:
k = int(input())

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

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

a = 1
ind = 1

print("here")

while (a % k != 0):
    a = a * 10 + 1
    ind += 1

print(ind)

Submission status: Runtime Error

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: Runtime Error

Solution code:
K = int(input())
if K==7 or K==1:
        print(1)
if K==11:
        print(2)
if K in (3,37,3*37):
    print(3)
elif K in (11,101,1111):
    print(4)
elif K in (41,271,11111):
    print(5)
elif K in (1, 3, 7, 11, 13, 21, 33, 37, 39, 77, 91, 111, 143, 231, 259, 273, 407, 429, 481, 777, 1001, 1221, 1443, 2849, 3003, 3367, 5291, 8547, 10101, 15873, 37037, 111111):
    print(6)
elif K in (239*4649):
    print(7)
else:
    print(-1)

Submission status: Runtime Error

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

main()

Submission status: Runtime Error

Solution code:
k = int(input())

l = len(list(str(k)))

ans = l
r = int('7' * (l-1))
x = 0

while(True):
    if x == (r * 10 + 7) // k and r == (r * 10 + 7) % k:
        print(-1)
        exit()

    x = (r * 10 + 7) // k
    r = (r * 10 + 7) % k

    if r == 0:
        break
    else:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
K = int(input())
mod = K
if K % 2 == 0 or K % 5 ==0:
    print(-1)
elif K % 7 != 0:
    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()
        elif X[i] == 1 % mod:
            loop = i
            print(loop * K)
            exit()
else:
    mod = K // 7
    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()
        elif X[i] == 1 % mod:
            loop = i
            print(loop * K)
            exit()

Submission status: Runtime Error

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):
    n = (n * 10 +7) % k
    if n % k==0:
      break
      
    cnt +=1
    
print(cnt)

Submission status: Runtime Error

Solution code:
k = int(input())

ans = 0
ai = 0

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

Submission status: Runtime Error

Solution code:
import math
# your code goes here
x = int(input())
i = 1
n= 0
if x % 2 == 0 or x % 5 == 0:
    print(-1)
else if: math.gcd(10,k)!=-1:
    print(-1)
else:
    for i in range(1, 1000000):

        l =( 7 %x*pow(9,-1)%x* (pow(10,i,x) - 1%x)%x )%x
        #l=math.ceil(l)
        
        n+=1
        
        if l % x == 0:
            break
    print(n)

Submission status: Runtime Error

Solution code:
# your code goes here
x = int(input())
i = 1
n= 0
if x % 2 == 0 or x % 5 == 0:
    print(-1)
else if: gcd(10,k)!=-1:
    print(-1)
else:
    for i in range(1, 1000000):

        l =( 7 %x*pow(9,-1)%x* (pow(10,i,x) - 1%x)%x )%x
        #l=math.ceil(l)
        
        n+=1
        
        if l % x == 0:
            break
    print(n)

Submission status: Runtime Error

Solution code:
# your code goes here
x = int(input())
i = 1
n= 0
if  gcd(10,x)!=1 or x % 2 == 0 or x % 5 == 0:
    print(-1)
else:
    for i in range(1, 1000000):

        l =( 7 %x*pow(9,-1)%x* (pow(10,i,x) - 1%x)%x )%x
        #l=math.ceil(l)
        
        n+=1
        
        if l % x == 0:
            break
    print(n)

Submission status: Runtime Error

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

    for i in range(1,k):
        t = "7"*i
        if str(t)%k==0 :
            print(i)
            break

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

Solution code:
!?!?

Submission status: Runtime Error

Solution code:
K = int(input())

# 循環が出てくるか確認すればよい

m = []
ans = -1
for i in range(1, 1000000):
  t = int('7' * i)
  k = t % K
  if k == 0:
    ans = i
    break
  if k in m:
    ans = -1
    break
  else:
    if i >= 2:
      if m[i] - m[i-1] >= 1
    m.append(k)

print(ans)

Submission status: Runtime Error

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: Runtime Error

Solution code:
#C

K=int(input())
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+2):
        p = (p*10+7)%K 
        #print(i,p)
        if p==0:
            ans=i
            break

print(ans)

Submission status: Runtime Error

Solution code:
#C

K=int(input())
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: Runtime Error

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: Runtime Error

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