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: Time Limit Exceeded

Solution code:
K = int(input())

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

k = 7
cnt = 1
while True:
  if k % K == 0:
    break
  k = (k * 10 + 7) % K
  cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/local/bin/python3
# coding: utf-8
import numpy as np

kita = int(input())
seven = ""
i = 0
while True:
    i += 1

    if kita % 2 == 0:
        print(-1)
        break
    if kita % 5 == 0:
        print(-1)
        break

    seven += "7"
    if int(seven) >= kita: 
        if int(seven) % kita == 0:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
def main():
    number=7   
    if K%2 == 0 or K%5 == 0:
        print(-1)
    else:
        s=1
        while True:
            if number%K == 0:
                print(s)
                break
            else:
                number=int(str(number)+"7")
                s += 1
                
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

cnt = 1
data = ""
if(K % 2 == 0):
	print(-1)
else:
	cnt = 1
	data = ""
	while(1):
		data = data + "7"
		datai = int(data)

		if((datai % K) == 0):
			print(cnt)
			break
		cnt = cnt + 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

num = 7
cnt = 1
if k % 2 == 0:
    print(-1)
elif k % 5 == 0:
    print(-1)
else:
    while True:
        if num % k == 0:
            break
        cnt += 1
        num = int(str(num) + '7')
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

num = 1
cnt = 1
if k % 7 ==0:
  k = k//7

while True:
  num = num % k
  if num == 0:
    print(cnt)
    break
  else:
    num += pow(10, cnt, k)
    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
import sys

K = int(input())
if K == 2:
    print(-1)
    sys.exit()
i = 1
pre = 7
while True:
    if pre % K == 0:
        print(i)
        break
    pre += 7*10**i
    i += 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

seq = '7'

while int(seq) % k != 0:
    seq += '7'

print(len(seq))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
n = 7
c = 1
while True:
  tmp = n % k
  if tmp == 0:
    print(c)
    break
  else:
    n = tmp * 10 + 7
    c += 1

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

k = ri()
a = k%10
if a in [1, 3, 7, 9]:
    s = 7
    while s%k:
        s = s*10 + 7
    print(math.ceil(math.log10(s)))
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
checker = False
for i in range(10 ** 6):
    n = int('7' * (i + 1))
    if n % K == 0:
        checker = True
        break
    
if checker:
    print(len(str(n)))
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
k= int(input())
if k % 2 == 0:
  print(-1)
i = 1
fav_num = 7
while True:
  if fav_num % k == 0:
    print(i)
    break
  fav_num = fav_num + 7*(pow(10,i))
  i = i + 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

count = 0
ans = 1

while True:
  num = int("7" + "7" * count)
  if k % 2 == 0 or k % 5 == 0:
    print(-1)
    break
  if num % k == 0:
    print(ans)
    break
  count += 1
  ans += 1

Submission status: Time Limit Exceeded

Solution code:
import re

def main():
    K = int(input())
    firstPlace = K % 10

    if firstPlace == 1:
        seed = 7
    elif firstPlace == 3:
        seed = 9
    elif firstPlace == 7:
        seed = 1
    elif firstPlace == 9:
        seed = 3
    else:
        return -1

    while True:
        verifiStr = str(K * seed)

        repattern = re.compile("^7+$")
        result = repattern.match(verifiStr)

        if result:
            return len(verifiStr)          

        seed = seed + 10

if __name__ == "__main__":
    answer = main()
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())

flag = 0
i = 0
seven = 7

if num % 2 == 0 or num % 5 == 0:
    flag = 1
    i = -1

while flag == 0:
    i += 1
    if seven % num == 0:
        flag = 1
    else:
        seven = seven * 10 + 7

print (i)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
sev = 7
seven = 0
s = 1
if K % 2 ==0:
    seven = 1
    count = -1
KK = K
while seven < 1 :
    while KK <= sev:
        if sev == KK:
            count = s
            seven = 1
        KK += K*2
    sev = sev * 10 + 7
    s += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
num = 0
K_s = len(str(K))
flg = 0

for i in range(K_s, 10**6):
    if K %2 == 0:
        print(-1)
        flg = 1
        break
    num = int(str(1)*i)
    if 7*num % K ==0:
        print(i)
        flg = 1
        break

if flg == 0:
    print(-1)

Submission status: Time Limit Exceeded

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

x = int('7'*len(str(K)))

while True:
    if x % K == 0:
        print(len(str(x)))
        exit()
    x = x * 10 + 7

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
if K%2==0:
  print(-1)
else:
  if K%7==0:
    K1=K//7
    x=1%K1
    z=1%K1
    y=1
    if x==0:
      print(1)
    else:
      while z>0:
          x=(x*10)%K1
          z+=x
          z%=K1
          y+=1  
      print(y)
  else:
    x=7%K
    z=7%K
    y=1
    if x==0:
      print(1)
    else:
      while z>0:
        x=(x*10)%K
        z+=x
        z%=K
        y+=1
      print(y)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
if not k&1:
    print(-1)
    exit()
ks=str(k)
carry=0
d1=int(ks[-1])
i=1
while i<=10**8:
    flag=False
    car=int(carry)
    for j in range(0,10):
        if (d1*j+car)%10==7:
            carry=str((car+k*j)//10)
            if len(carry)==carry.count('7'):
                print(i+len(carry))
                exit()
            flag=True
            break
    if not flag:
        print(-1)
        exit()
    i+=1

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

v = "7"
if K % 2 == 0:
  print(-1)
  exit()

c = 1
while int(v)%K != 0:
  v += "7"
  c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
# 
#     if temp!=1:
#         arr.append([temp, 1])
# 
#     if arr==[]:
#         arr.append([n, 1])
# 
#     return arr

def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    # if is_prime(k):
    #     print(k-1)
    sevens = 0
    for i in range(k):
        sevens = sevens*10+7
        if sevens%k == 0:
            print(i+1)
            return
    print(k-1)

def main2():
    print(777777777%9)
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from typing import List
import math


def solution(K: int) -> int:
    ans: int = 0
    x: int = 7
    while True:
        # print(x)
        # print()
        ans += 1
        # K が偶数の時
        if K % 2 == 0:
            return -1
        # x が K より小さい時
        if x < int(K):
            x: int = int(str(x) + str(7))
            continue
        if x % K == 0:
            return ans
        if K < ans:
            return -1
        x: int = int(str(x) + str(7))
    return ans


K: int = int(input())

print(solution(K))

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
 
 
def make_divisors(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table
 
 
a = 1
n = 7
l = 10 ** 20
p = X % 2
 
while True:
    if p == 0:
        print(-1)
        break;
    m = make_divisors(n)
    if X in m:
        print(a)
        break;
    if n > l:
        print(-1)
        break;
    else:
        a += 1
        n = n * 10 + 7

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
if k % 2 == 0:
    print("-1")
else:
    seven = "7"
    point = False
    for i in range(1000000):
        if int(seven) % k == 0:
            point = True
            break
        else:
            seven += "7"
    if point:
        print(len(seven))
    else:
        print("-1")

Submission status: Time Limit Exceeded

Solution code:
import sys

K = int(input())

seven = 7 % K
mod = 7 % K
for i in range(10**7):
    if seven % K == 0:
        print(i+1)
        sys.exit()
    else:
        seven = seven * (10 % K) + mod

print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
n = 1
list = []
r = 7
while True:
    r = r % k
    if r == 0:
        print(n)
        break
    elif r in list:
        print(-1)
        break
    else:
        list.append(r)
        r = r * 10 + 7
        n += 1

Submission status: Time Limit Exceeded

Solution code:
k = input()
x = 0
if int(k[-1]) % 2 == 0 or int(k[-1]) % 5 == 0:
    print("-1")
else:
    k = int(k)
    for i in range(1,abs(k) + 1):
        x += 7 * pow(10,i - 1)
        if x % k == 0:
            print(i)
            break
    else:
        print("-1")

Submission status: Time Limit Exceeded

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

x = 7
ans = 1
while x > 0:
    if x < K:
        x = x*10 + 7
        ans += 1
        continue
    x = x % K

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def f(K):
    ans = '-1'
    for k in range(1,K+1):
        a = int('7'*k)
        if a%K == 0:
            ans = k
            break
    return ans
K = int(input())
print(f(K))

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
b = 0
ans = -1
for i in range(10000000):
  b = b*10 + 7
  if b % n == 0:
    ans = i+1
    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())


x = 1
y = 7

if k % 2 == 0:
    print(-1)
else:
    while True:
        if y % k == 0:
            print(x)
            break
        else:
            y = y*10 +7
            x += 1

Submission status: Time Limit Exceeded

Solution code:
s = [input() for i in range(1)] 
k = int(s[0])

base_number = 0
if k % 2 == 0:
    print("-1")
if k % 2 == 1:
    for i in range(100000000):
        base_number += 7 * (10 ** i)
        q, mod = divmod(base_number, k)
        if mod == 0:
            print(i+1)
            break

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

sbox=[]
for i in range(1,k+1):
    x=0
    while i>=1:
        x=x*10+7
        i-=1
    surplus=x%k
    if surplus==0:
        print(len(str(x)))
        break
    else:
        if surplus in sbox:
            print(-1)
            break
        else:
            sbox.append(surplus)
    if k==len(str(x)):
        print(-1)
        break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
k = int(input())

Moji = ''
if k % 2 ==0:
  print(-1)
elif str(k)[0] == 5:
  print(-1)
elif k  < np.sqrt(777777777777777.0):
  for i in range(10**6):
    Moji += '7'
    if int(Moji)%k == 0:
      print(i+1)
      break
      
else:
  print(k-1)

Submission status: Time Limit Exceeded

Solution code:
K=input()
if int(K)%2==0 or K[-1]==5:
    print(-1)
else:
    for i in range(9999999999999):
        b=i**4+i**9

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
k = int(input())

Moji = ''
if k % 2 ==0:
  print(-1)
elif str(k)[0] == 5:
  print(-1)
elif k  < np.sqrt(77777777777777777777.0):
  for i in range(10**6):
    Moji += '7'
    if int(Moji)%k == 0:
      print(i+1)
      break
      
else:
  print(k-1)

Submission status: Time Limit Exceeded

Solution code:
a = 7
num = 0
cnt = 1
b=int(input())
if b%2==0:
    num=-1
else:
    while True:
        if b*cnt==a:
            num=cnt
            break
        cnt += 1
        a = a*10+7    
print("{}".format(num))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
k=int(input())
if not k&1:
    print(-1)
    exit()
ks=str(k)
tmp=-1
carries=deque()
carries.append(0)
d1=int(ks[-1])

mul=0
i=1
while i<10**7:
    flag=False
    car=carries.pop()
    for j in range(0,10):
        if (d1*j+car)%10==7:
            cr=(car+k*j)//10
            if len(str(cr))==str(cr).count('7'):
                print(i+len(str(cr)))
                exit()
            carries.append(cr)
            flag=True
            break
    if not flag:
        print(-1)
        exit()
    i+=1

Submission status: Time Limit Exceeded

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

    keta = 1
    N_try = 10 ** 6

    for i in range(N_try + 1):
        tmp = '1' * keta
        number = ((int(tmp) % K) * 7) % K
        
        if (number == 0):
            print(keta)
            exit()

        else:
            keta += 1
            

    print(-1)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

k_ = str(k)

if k%2 == 1:
    if k_[-1] == str(5):
        cnt = -1
        print(cnt)
        exit()
else:
    cnt = -1
    print(cnt)
    exit()

s = 7

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
X = int(input())

if X%2==0:
  print(-1)
  sys.exit()
else:
  cnt=0
  ans=[]
  length = X
  S = "7"*length
  while int(S)>=7:
    cnt+=1
    if math.gcd(X,int(S)) == X:
      ans.append(length)
      length -=1
      S = "7"*length
    else:
      length -=1
      S = "7"*length
    if not S.isdigit():
      break
if ans:
  print(min(ans))
else:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
def main():
    K = int(input())
    firstPlace = K % 10

    if firstPlace == 1:
        seed = 7
    elif firstPlace == 3:
        seed = 9
    elif firstPlace == 7:
        seed = 1
    elif firstPlace == 9:
        seed = 3
    else:
        return -1

    while True:
        verifiStr = str(K * seed)
        lenVerifiStr = len(verifiStr)

        if(verifiStr.count("7") == lenVerifiStr):
            return lenVerifiStr           

        seed = seed + 10

if __name__ == "__main__":
    answer = main()
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
K = int(input())
# = "7"*999982
#print(int(t)%999983)
if K%2 == 0 or K%5 == 0:
    print(-1)
else:
    i = 0
    while(1):
        i+=1
        if 7 * (10**i-1)//9 %K == 0:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

A = 7
ans = 1
while(A < K): #O(6)
    A = A*10 + 7
    ans += 1

while(True):
    #print(A)
    A = A % K #1
    if(ans > K):
        print("-1")
    if(A==0): #1
        print(ans)
        exit()
    A = A * 10 + 7 # 1
    ans += 1# 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
num = k
count = 1
jud = 7

if k % 2 == 0:
    print(-1)
else:
    while jud % k != 0:
        count+=1
        jud = jud*10 + 7
    else:
        print(count)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

if k % 2 == 0:
  print(-1)
else:
  i = 0
  n = 0
  f = False
  while f == False:
    n += (10 ** i) * 7
    if n % k == 0:
      print(i+1)
      f = True
    i += 1

Submission status: Time Limit Exceeded

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

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

print(-1)

Submission status: Time Limit Exceeded

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

K = int(input())
for i in range(1, 20):
    if K % 2 == 0:
        print('-1')
        break
    lis=[]
    lis.append(make_divisors(int('7'*i)))
    if K in lis:
        print(i)
        break
else:
    print(K-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

K = int(input())

seven = 7
for i in range(10**6):
    if seven % K == 0:
        print(i+1)
        sys.exit()
    else:
        seven = seven * 10 + 7

print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

count = 0
ans = 1

while True:
  num = int("7" + "7" * count)
  if k % 2 == 0 or str(k)[-1] == "5":
    print(-1)
    break
  if num % k == 0:
    print(ans)
    break
  count += 1
  ans += 1

Submission status: Time Limit Exceeded

Solution code:
import sys
K = int(input())
flag = 0
flag7 = 0
if K%2 ==0:
  flag=1
for i in range(10):
  temp = str(K*i)
  if int(temp[len(temp)-1])==7:
  	flag7 = 1
if flag == 1 or flag7==0:
  print(-1)
  sys.exit()
count = 1
num_7 = 7

while(count<10000000000):
  flag = 0
  temp = K*count
  for i in range(10):
    if i == 7:
      continue
    if str(i) in str(temp):
      flag=1
      break
  
  if flag == 0:
    print(len(str(temp)))
    sys.exit()
  count+=1

Submission status: Time Limit Exceeded

Solution code:
val = int(input());
tmp = 7;
cnt = 1;
flg = 0;

while flg==0 and cnt<1000000:
    if(tmp%val == 0):
        flg=1;
    else :
        tmp=tmp*10+7;
        cnt=cnt+1;

if(flg==0):
    print(-1);
else:
    print(cnt);

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
a=7
i=1
while i <= 20000:
  if a%k ==0:
    print(i)
    break
  elif i==20000 and a%k !=0:
    print("-1")
    break
  i+=1
  a = a + 7*10**(i-1)

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

INF = 10**9+7

if __name__ == "__main__":
    k = int(input())
    if k%2 == 0:
        print(-1)
        sys.exit()
    cnt = 1
    a = 7
    while a<10**100000+1:
        if a%k == 0:
            print(cnt)
            sys.exit()
        a*=10
        a+=7
        cnt+=1
    print(k-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
# print(str(K))

if str(K)[-1] in {"0","2","4","5","6","8"}:
  print("-1")
else:
  target  = "7"
  counter = 1
  while True:
    if int(target) % K == 0:
      print(str(counter))
      break
    target  = target + "7"
    counter = counter + 1

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
number=7
if K%2 == 0 or K%5 == 0:
    print(-1)
else:
    s=1
    while True:
        if number%K == 0:
            print(s)
            break
        else:
            number=int(str(number)+"7")
            s += 1

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

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

loop=10**6

for i in range(1, loop):
    a_n=(10**i -1)//9
    a_n*=7

    if a_n%K==0:
        print(i)
        exit()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

A = 7
ans = 1
while(A < K):
    A = A*10 + 7
    ans += 1

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

k = int(input())
if k%2==0:
    print(-1)
else:
    ret = 1
    res = 7%k
    while res != 0:
        res = (res * 10 + 7)%k
        ret += 1
    print(ret)

Submission status: Time Limit Exceeded

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

x = 7
ans = 1
while True:
    if x < K:
        x = x*10 + 7
        ans += 1
        continue
    q,m = divmod(x,K)
    if m == 0:
        break
    x = m
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
if  k%2==0 or k%5==0:
    print(-1)
else:
    K = int(str(k)[-1])
    # print(K)
    if K==1:
        # print("a")
        x = 7
    elif K==3:
        x=9
    elif K==7:
        x = 1
    elif K==9:
        x = 3
    z = 0
    # print(x)
    while True:
        s = 10*z + x
        q = k * s
        if str(q)=="7"*len(str(q)):
            print(len(str(q)))
            break
        z+=1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def cal(num, k):
    i = 1
    while True:
        if num % k == 0:
            print(i)
            break
        else:
            num = num * 10 + 7
            i += 1

if k % 2 == 0:
    print(-1)
else:
    cal(7, k)

Submission status: Time Limit Exceeded

Solution code:
import sys

K = int(input())

seven = 7
for i in range(10**7):
    if seven % K == 0:
        print(i+1)
        sys.exit()
    else:
        seven = seven * 10 + 7

print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
if __name__=='__main__':
  k=int(input())
  c=1
  n=7
  flag=0
  for i in range(1000000):
    if n%k==0:
      print(c)
      flag=1
      break
    else:
      n=n*10+7
      c+=1
  if flag ==0:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

K = int(stdin.readline().rstrip())
a_n = 7
i = 1
while True:      
  if a_n % K == 0:
    break
  else:
    i += 1
    a_n = a_n * 10 + 7
    
print(i)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

seven=[]
nana='7'

is_OK=0
for k in range(1,10):
    tmp=K*k
    s_tmp=str(tmp)
    # print(s_tmp[-1])
    if s_tmp[-1]=='7':
        is_OK+=1

if is_OK==0:
    print('-1')
    exit()

# seven.append(int(nana))
i=1

while 1:
    n=K*i
    s_n=str(n)
    num=list(s_n)
    if (all(x == '7' for x in num)):
        print(len(str(n)))
        exit()
    i=i+1

# while 1:
#     nana=nana+'7'
#     nana=int(nana)
#     seven.append(nana)
#
#     if nana%K==0:
#         print(i)
#         exit()
#     nana = str(nana)
#     i+=1
#     if i ==100000:
#         print('aa')
# print(seven)

Submission status: Time Limit Exceeded

Solution code:

import sys

a = [2,4,5,6,8,0]
N = input()

Q = len(N) * "7"

# print(Q)

if int(N[-1]) in a :
    print(-1)
    sys.exit()
    
N = int(N)

K = "7"

for i in range(20000):
    S = int(K)
    if S % N == 0:
        print(len(K))
        sys.exit()
    K = K + Q
# print(len(K))
print(-1)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())


def make_divisors(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table


a = 1
n = 7
l = 10 ** 18
p = X % 2

while True:
    if p == 0:
        print(-1)
        break;
    m = make_divisors(n)
    if X in m:
        print(a)
        break;
    if n > l:
        print(-1)
        break;
    else:
        a += 1
        n = n * 10 + 7

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
a=7
i=1
while i <= 30000:
  if a%k ==0:
    print(i)
    break
  elif i==30000 and a%k !=0:
    print("-1")
    break
  i+=1
  a = a + 7*10**(i-1)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())


def get(k):
    ans=7
    i=1
    while True:
        if ans%k==0:
            return i
        ans=(ans*10+7)%k
        i+=1




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

else:
    print(get(k))

Submission status: Time Limit Exceeded

Solution code:
import sys,os
import math

K = int(input())

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

n = int (math.log10(K) + 1)

while(1):
    target = int("".join(["7"]*n))
    if target%K == 0:
        print(n)
        break
    n += 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
seven = 7
i = 1
if k % 2 == 0:
    print(-1)
else:
    while seven < k:
        seven = seven + 7 * 10**i
        i +=1
        ans = seven
        
    while seven % k != 0:
        seven = seven + 7 * 10**i
        i +=1
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys
def resolve():
    K = int(input())
    if K%2 == 0:
        print(-1)
        sys.exit()
    else:
        num = 7
        count = 1
        for _ in range(K):
            if num>=K:
                if num%K == 0:
                    print(count)
                    sys.exit()
                else:
                    num = num*10 + 7
                    count += 1
            else:
                num = num*10 + 7
                count += 1
        print(-1)
        sys.exit()
resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

if K % 2 == 0:
  print(-1)
elif K % 5 == 0:
  print(-1)
else :
  cnt = 1
  sevens = 7
  while sevens % K != 0 :
    cnt += 1
    sevens *= 10
    sevens += 7
  
  print(cnt)

Submission status: Time Limit Exceeded

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

def seven(n):
    a = 0
    for i in range(1,n+1):
        a += 10**(i-1) * 7
    return a        

def main():
    ans = 0
    i = 1
    if K %2 == 0:
        ans = -1
    else:
        while True:
        #for _ in range(10):
            num = seven(i)
            a = K * num
            b = [int(x) for x in list(str(a))]
            if numpy.all(numpy.array(b) == 7):
                ans = len(b)
                break
            else:
                i += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def isMultiple(s, m):
    tmp = 0
    for i in range(len(s)):
        tmp = (tmp * 10 + int(s[i])) % m
        if tmp == 0:
            return i
    return -1


k = int(readline())
acc = "7" * 10000000
if k % 2 == 0:
    ans = -1
else:

    ans = isMultiple(acc, k) + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
ans = -1
q = int(str(k)[-1])
l = {1: 7, 3: 9, 7: 1, 9: 3}
if q in l:
  f = 0
  m = 1
  seven = ['7']

  m = l[q]
  p = list(set(list(str(k * m))))
  while f == 0:
    if seven == p:
      ans = len(str(k * m))
      break
    else:
      m += 10
      p = list(set(list(str(k * m))))
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(1,K+1):
    cc=int('7'*i)
    if cc%K==0:
        ans=i
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
count = 1
if K%2 != 0 and K%5 != 0:
    while True:
        a = 0
        for i in range(count):
            a += 7*(10**i)
        if a%K == 0:
            print(count)
            break
        else:
            count += 1
            continue

else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
cur = 7
ok = 0
while(ok==0 & len(str(cur))<=2000000):
    if(cur % a == 0):
        ok = 1
    else:
        cur = cur*10 + 7

if(ok == 1):
    print(len(str(cur)))
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()
else:
    n = 7
    n_before = 7
    count = 1
    while n % K != 0:
        n = n % K
        count += 1
        n_before = 10 * n_before % K
        n = n + n_before
print(count)

Submission status: Time Limit Exceeded

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

import sys

def main():
    k = int(input())
    mod=10**9+7
    if k % 2==0:
        print(-1)
        exit()

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

if __name__ == "__main__":
    main()