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

def seven():
    seven_i = 0
    SEVEN = list()
    count = 0
    for i in range(K):
        seven_i += (10**i*7)
        SEVEN.append(seven_i)
        count += 1
        if SEVEN[i] % K == 0:
            return count
    return -1

print(seven())

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
ans=1
s_1=7%k
s_2=10%k
m=0
j=0
if k%2==0 or k%5==0:
  print(-1)
elif k==1 or k==7:
  print(1)
else:
  i=0
  while j==0:
    m=(m+(s_1*(((s_2)**i)%k)))%k
    if m==0:
      j==1
    else:
      ans+=1
      i+=1
  print(ans)

Submission status: Time Limit Exceeded

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

flg = True
for i in range(1,10**12):
  x = x%k
  if x ==0:
    break
  else:
    x = x*10+7
    
if k%2==0:
  flg = False
    
print(i if flg else '-1')

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

sevens = 0
count = 0
repeat = True

if {K%10} & {0,2,4,5,6,8}:
    count = -1
    repeat = False

while repeat:
    sevens = sevens * 10 + 7
    count += 1
    if sevens % K == 0:
        repeat = False

print(count)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
n = 1000000

if K % 2 == 0:
    print(-1)
elif K % 7 == 0:
    amari = 10
    for i in range(K):
        if amari % int(9 * (K / 7)) == 1:
            print(i + 1)
            break
        else:
            amari = amari * 10
else:
    amari = 70
    for i in range(K):
        if amari % int(9 * K) == 7:
            print(i + 1)
            break
        else:
            amari = amari * 10

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
n = 1000000

if K % 2 == 0:
    print(-1)
elif K % 7 == 0:
    amari = 10
    for i in range(n):
        if amari % int(9 * (K / 7)) == 1:
            print(i + 1)
            break
        else:
            amari = amari * 10
else:
    amari = 70
    for i in range(n):
        if amari % int(9 * K) == 7:
            print(i + 1)
            break
        else:
            amari = amari * 10

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
n = 7
c = 1
flag = []
while True:
    r = n % a
    if r == 0:
        print(c)
        break
    n = r * 10 + 7
    c += 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

L = 9*K
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    K = int(input())
    x = 0
    i = 0
    if K % 2 == 0 or K % 5 ==  0:
        print(-1)
        exit()
    
    while True:
        x = (x + 7 * 10 ** i) % K
        i += 1
        if x == 0:
            print(i)
            break


    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
C=False
count=0
for i in range(1,K+1):
  count+=1
  if (7*(10**i-1))%(9*K)==0:
    C=True
    break
  elif K%2 == 0 or K%5 == 0:
    break
if C:
  print(count)
else:
  print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

k = int(input())

cnt = 1
mod = 7

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

if mod%k == 0:
    print(cnt)
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
first_mod = 7 % k
mod = first_mod
ans = -1
i = 0
state = "first_state"
while state != first_mod:
  i += 1
  if mod == 0:
    ans = i
  mod = (mod * 10 + 7) % k
  state = mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
i = 0
first_mod = 7 % k
mod = first_mod
ans = -1
state = "first_state"
while state != first_mod:
  i += 1
  if mod == 0:
    ans = i
  mod = (mod * 10 + 7) % k
  state = mod

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
s=7
x=10000000
for i in range(x):
    if(s%k==0):
        print(i+1)
        break
    s=s*10+7
if(s%k!=0):
    print("-1")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a=0
flag=0
for i in range(1,N+1):
    a=(a*10)+7
    p=a%N
    if p==0:
        print(i)
        flag=1
        break

if flag==0:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
s = True
i = 0
f_m = 7 % k
mod = f_m
while s:
  i += 1
  if mod == 0:
    s = False
  elif i > 1 and mod == f_m:
    s = False
    i = -1
  mod = (mod * 10 + 7) % k
print(i)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

L = 9*K
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
state = True
i = 0
sevens = 7
first_mod = 7 % k
mod = first_mod
while state:
  i += 1
  if mod == 0:
    state = False
  elif i > 1 and mod == first_mod:
    state = False
    i = -1
  mod = (mod * 10 + 7) % k
print(i)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    K = int(input())
    x = 0
    
    if K % 2 == 0 or K % 5 ==  0:
        print(-1)
        exit()
 
    for i in range(K):
        amari = (7 * 10 ** i) % K
        x = x + amari
        if x % K == 0:
            print(i + 1)
            break
        x = x % K
   


    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    K = int(input())
    x = 0
    i = 0
    if K % 2 == 0 or K % 5 ==  0:
        print(-1)
 
    while True:
        x = (x * 10 + 7) % K
        i += 1
        if x == 0:
            print(i)
            break


    

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[32]:


K = int(input())


# In[33]:


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


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
if k%2 == 0:
    print("-1")
else:
    n = '7'
    cnt = 1
    while 1 :
        if int(n)%k == 0:
            print(cnt)
            break
        n += '7'
        cnt += 1

Submission status: Time Limit Exceeded

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

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

if L%2==0 or L%5==0:
    print(-1)
else:
    num=1
    while 10**num%L!=1:
        num+=1
    print(num)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
i = 1
n= 0
b=0
if x % 2 == 0 or x % 5 == 0:
    print(-1)
else:
    for i in range(1, 1000000):

        l = (7 * (10**i - 1) // 9)%x
        n+=1
        if l % x == 0:
            b=1
            break
    if b==1:  
      
      
      print(n)
    else:
      print (-1)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
i = 1
n= 0
if x % 2 == 0 or x % 5 == 0:
    print(-1)
else:
    for i in range(1, 1000000):

        l = (7 * (10**i - 1) // 9)%x
        n+=1
        if l % x == 0:
            break
    print(n)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
i = 1
n= 0
if x % 2 == 0 or x % 5 == 0:
    print(-1)
else:
    for i in range(1, 1000000):

        l = 7 * (10**i - 1) // 9
        n+=1
        if l % x == 0:
            break
    print(n)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
i = 1
n= 0
if x % 2 == 0:
    print(-1)
else:
    for i in range(1, 1000000):

        l = 7 * (10**i - 1) // 9
        n+=1
        if l % x == 0:
            break
    print(n)

Submission status: Time Limit Exceeded

Solution code:
k=input()
r=int(k)
s=7
j=0
l=len(k)-1
if(r%2==0):
  print("-1")
elif(k[l]=='1' or k[l]=='3' or k[l]=='7' or k[l]=='9'):
    while(1):
        j=j+1
        if(s%r==0):
            break
        s=s*10+7
    print(j)
else:
    print("-1")

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
s=7
j=0
if(k%2==0):
  print("-1")
else:
    while(1):
        j=j+1
        if(s%k==0):
            break
        s=s*10+7
    print(j)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
Judge = True
remain_initial = 7 % K
remain = 0
i = 0

while Judge == True:
    i += 1
    remain_str = str(remain) + '7'
    number = int(remain_str)
    remain = number % K

    if number % K == 0:
        Judge = False
        answer = i

    elif i == 1:
        continue

    elif number % K == remain_initial:
        Judge = False
        answer = -1

print(answer)

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    K = int(input())
    if K%2==0:
        return print(-1)
    seven = 0
    ans = 0
    while True:
        seven = (seven * 10 + 7) % K
        ans += 1
        if seven == 0:
            break
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

mod_list = []
if N % 2:
    i = 1
    while True:
        num = (7*((10**i)-1)//9) % N
        # print(num)
        if num == 0:
            print(i)
            break
        if num in mod_list:
            print(-1)
            break
        else:
            mod_list.append(num)
            i += 1

else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
sevens = ['7']
result = -1
if not k % 2 == 0 and not k % 5 == 0:
    for i, _ in enumerate(range(k), 1):
        val = int(''.join(sevens))
        if val % k == 0:
            result = i
            break
        else:
            sevens.append('7')
print(result)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
num = 7%k
i = 1
num_sum = num
while True:
  if num_sum == 0:
    print(i)
    break
  i = i+1
  num_sum = num * i
else:
  print('-1')

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
num = 7%k
if k % 2 == 0:
  print('-1')
i = 1
num_sum = num
while True:
  if num_sum == 0:
    print(i)
  i = i+1
  num_sum = num * i

Submission status: Time Limit Exceeded

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

k = int(input())
rs = []
n = 0 

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

    if n in rs: 
        print(-1)
        exit()

    rs.append(n)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
su = 0
sum = []
for i in range(0,s):
    su=su*10+7
    if su not in sum:
        sum.append(su)
for i in range(len(sum)):
    if sum[i]%s==0:
        print(i+1)
        exit()
for j in sum:
    if j%s !=0:
        continue
print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
s = 7
counter = 0
mod_box=[]


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

else:
    m = s % k
    counter += 1
    if m == 0:
        print(counter)
    else:
        while True:
            mod_box.append(m)
            m = (10 * m + 7) % k
            counter += 1
            if m == 0:
                print(counter)
                break
            elif m in mod_box:
                print(-1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

cnt = 1
sevens = 0

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

Submission status: Time Limit Exceeded

Solution code:
#C_Repsept
import math
K = int(input())
X = 0
kekka = -1
total = -1
if K % 2 == 1:
    for i in range(K): 
        X = X + pow(10,i) * 7
        kekka = X % K
        if kekka == 0:
            total = i+1
            break
# 出力
print(total)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()
ans = 1
mod = 7 % K
while mod != 0:
    mod = (mod * 10 + 7) % K
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
if K%2==0:
  print(-1)
else:
  ans=0
  c=0
  for i in range(10**7):
    ans+=7*pow(10,i)
    c+=1
    if ans%K==0:
      print(c)
      exit()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

elif (K%10) % 5 == 0:
    pass
    print(-1)
else:
    num = 7
    for i in range(K+1):
        if num % K == 0:
            print(str(i+1))
            break
        num = num *10 + 7
    else:
        print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
s = 7
counter = 0
mod_box=[]


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

else:
    m = s % k
    counter += 1
    if m == 0:
        print(counter)
    else:
        mod_box.append(m)
        while True:
            m = 10 * m + 7
            m = m % k
            counter += 1
            if m == 0:
                print(counter)
                break
            elif m in mod_box:
                print(-1)
            else:
                mod_box.append(m)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

X = 7 % K
S = []
i = 1
while S.count(X) == 0:
  if X == 0:
    count = i
    print(count)
    exit()
  S.append(X)
  X = (X*10 + 7) % K
  i += 1

print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
number = 7
cnt = 1
answer = -1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

mod_ini = 7%K
mod = 0
cnt = 0

while True:
    if K%2 == 0:
        print(-1)
        break
    
    cnt += 1
    mod = (mod*10 + 7)%K
    #print(mod)
    
    if mod == 0:
        print(cnt)
        break
    elif mod == mod_ini and cnt != 1:
        print(-1)
        break

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

mod_ini = 7%K
mod = 0
cnt = 0

while True:
    cnt += 1
    mod = (mod*10 + 7)%K
    #print(mod)
    
    if mod == 0:
        print(cnt)
        break
    elif mod == mod_ini and cnt != 1:
        print(-1)
        break

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
x = 0
i = 1
mx = []
while (True):
  x = 10 * x + 7
  mk = x % k
  if mk in mx:
    print(-1)
    break
  if mk == 0:
    print(i)
    break
  mx.append(mk)
  i += 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
x=7
cnt=1
if k%2==0:
    print(-1)
else:
    while True:
        if x % k ==0:
            print(cnt)
            break
        elif cnt<10000000:
            x=(x+7*(10**cnt)%k)%k
            cnt+=1
        else:
            print(-1)
            break

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
k=int(input())
i=1
s=7
while True:
  m=s%k
  if m==0:
    print(i)
    break
  s=m*10+7
  i+=1

Submission status: Time Limit Exceeded

Solution code:
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

K = int(input())
 
seven = "7"
flag = 1

if K%2==0:
	print(-1)
	
else:
	for i in range(1,10*8):
		#print(factorize(int(seven*i)))
		if K in factorize(int(seven*i)):
			print(i)
			flag=0
			break
	
	if flag:
		print(-1)

Submission status: Time Limit Exceeded

Solution code:
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

K = int(input())
 
seven = "7"
flag = 1

if K%2==0:
	print(-1)
	
else:
	for i in range(1,10*15):
		#print(factorize(int(seven*i)))
		if K in factorize(int(seven*i)):
			print(i)
			flag=0
			break
	
	if flag:
		print(-1)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
n=10**6

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
k=int(input())
if k%7==0:
  l=9*k/7
else:
  l=9*k
if l%2==0 or l%5==0:
  print(-1)
i=1
while True:
  s=10**i
  if l<=s:
    break
  i+=1
while True:
  j=s%l
  if j==1:
    print(i)
    break
  i+=1
  s=j*10

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
k=int(input())
if k%7==0:
  l=9*k/7
else:
  l=9*k
if l%2==0 or l%5==0:
  print(-1)
i=1
s=10
while True:
  j=s%l
  if j==1:
    print(i)
    break
  i+=1
  s=j*10

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

res = -1
count = 0
ai = 0
while(True):
    ai = (ai*10 + 7) % K
    count += 1
    if(ai == 0):
        res = count
        break

print(res)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

sevens = int('7' * len(str(K)))
flag = False
for i in range(K):
    if sevens % K == 0:
        flag = True
        break
    sevens = sevens * 10 + 7
print(len(str(sevens)) if flag else -1)

Submission status: Time Limit Exceeded

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

k = inp()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

k = 7
m = k%n
if m == 0:
    print(1)
    exit()
cnt = 1

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

Submission status: Time Limit Exceeded

Solution code:
# C - Repsept
def main():
    K = int(input())
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return 
    
    cnt = 0
    while True:
        cnt += 1
        if int("7" * cnt) % K == 0:
            print(cnt)
            break


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# C - Repsept
def main():
    K = int(input())
    cnt = 0
    while cnt < 10 ** 7:
        cnt += 1
        if int("7" * cnt) % K == 0:
            print(cnt)
            return 
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# C - Repsept
def main():
    K = int(input())
    cnt = 0
    while cnt < 5 * 10 ** 7:
        cnt += 1
        if int("7" * cnt) % K == 0:
            print(cnt)
            return 
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# C - Repsept
def main():
    K = int(input())
    if K % 2 == 0:
        print(-1)
        return 
    
    cnt = 0
    while True:
        cnt += 1
        if int("7" * cnt) % K == 0:
            print(cnt)
            break


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

  t = t * 10 + 7
  
else:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
from math import gcd
K=int(input())
if K%7==0:
  K=K//7
if gcd(10,K)!=1:
  print(-1)
  exit
x=1%K
cnt=1
while x!=0:
  x=(10*x+1)%K
  cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
x = 7 % K #mod(K)
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
while True:
  ans += 1
  x = (x * 10 + 7) % K
  
  if x == 7 % K:
    print('-1')
    exit()
  if x == 0:
    print(ans)
    exit()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
Seq = 7
ans = 1
f = 0

for i in range(10 ** 6):
    if Seq % K == 0:
        print(ans)
        f = 1
    Seq = (Seq * 10) + 7
    ans += 1
    
if f != 1:
    print("-1")

Submission status: Time Limit Exceeded

Solution code:
import sys

K = int(input())
num = 7
cnt = 0
Len = len(str(K))

for n in range(0,10000000):
    cnt += 1
    if (int(num)%K)==0:
        ans = int(num) % K
        break
    else:
        num = num * 10 + 7
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
s = 7
ans = 1
while ans < 10 ** 6:
    if s % k == 0:
        print(ans)
        quit()
    s = s * 10 + 7
    ans += 1
print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
seven = 7
count = 0

if(K % 2 == 0 or K % 5 == 0):
    print(-1)
if(K == 7 or K == 1):
    print(1)
else:
    while(seven % K != 0):
        seven = (seven * 10 + 7) % K
        count += 1
    print(count+1)
    """
    for i in range(1,10**6):
        seven = (seven * 10 + 7) % K
        if(seven % K == 0):
            print(i+1)
            break
    """

# これだと10^5以降の計算が遅くなる。countのせい？？
# count += 1
# seven = seven + 7 * (10 ** count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
seven = 7
count = 0

if(K % 2 == 0 or K % 5 == 0):
    print(-1)
if(K == 7):
    print(1)
else:
    while(seven % K != 0):
        seven = (seven * 10 + 7) % K
        count += 1

        # これだと10^5以降の計算が遅くなる。countのせい？？
        # count += 1
        # seven = seven + 7 * (10 ** count)
    print(count+1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
if K % 2 == 0:
    print(-1)
else:
    mod, modt, ans = 7 % K, 7 % K, 1
    while mod != 0:
        modt = (modt * (10 % K)) % K
        mod, ans = (mod + modt) % K, ans + 1
    print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


def main():
    K = I()
    if K % 2 == 0 or K %  5 == 0:
        print(-1)
        exit()
    if K % 7 == 0:
        K = 9*K//7
    else:
        K = 9*K
    amari = 1
    num = 1
    for i in range(10**6):
        num *= 10
        amari = amari*10 % K        
        if amari == 1:
            print(i+1)
            exit()
    print(-1)

main()

Submission status: Time Limit Exceeded

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


def main():
    K = I()
    result = -1
    num = 1
    if K % 2 == 0 or K %  5 == 0:
        print(-1)
        exit()
    if K % 7 == 0:
        K = 9*K//7
    else:
        K = 9*K
    for i in range(10**6):
        num *= 10
        if num % K == 1:
            print(i+1)
            exit()
    print(-1)
            

main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

for i in range(1, l + 1):
    m = pow(10, i, l)
    if m == 1:
        print(i)
        break
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
seven = 7
count = 0

for _ in range(1000000):
    if k % 2 == 0:
        count = -1
        break

    elif seven % k == 0:
        count += 1
        break
    else:
        count += 1
        seven = seven * 10 + 7

print(count)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
seven = 7
count = 0

while True:
    if k % 2 == 0:
        count = -1
        break

    elif seven % k == 0:
        count += 1
        break
    else:
        count += 1
        seven = seven * 10 + 7

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

l = 0
if k % 7 == 0:
    l = 9 * k // 7
else:
    l = 9 * k

for i in range(1, l + 1):
    m = pow(10, i, l)
    if m == 1:
        print(i)
        break
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
x = 7%k
s = []

while s.count(x) == 0:
  s.append(x)
  if x == 0:
    print(len(s))
    break
  x = (10*x + 7)%k

  
if s[-1] != 0:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
b = 7
c = 1
a = []
a.append(7)
if(k%2 == 0):
  print(-1)
else:
  while(b%k != 0):
    r = b%k
    b = 10*r+7
    c += 1
  a.append(b)
  print(c)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
x = 7%k
s = []
if k%2 == 0:
  print(-1)

else:
  while s.count(x) == 0:
    s.append(x)
    if x == 0:
      print(len(s))
      break
    x = (10*x + 7)%k

  
  if s[-1] != 0:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

num = 1 
n = 7
x = True
 
if (k%2 == 0):
  x = False
  print(-1)

while x:
  if (n%k == 0):
    print(num)
    break
  else:
    n = (n*10 + 7)%k
    num += 1

Submission status: Time Limit Exceeded

Solution code:
def main():
    K = int(input())
    first = 7 % K
    curr = first
    yet = True
    ans = 1
    while yet:
        if curr == 0:
            print(ans)
            return
        curr = (curr*10+7) % K
        if first == curr:
            yet = False
        ans += 1
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

if ans == 0:
    print("-1")
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    K = int(input())
    first = 7 % K
    curr = first
    S = set()
    ans = 1
    while first not in S:
        if curr == 0:
            print(ans)
            return
        curr = (curr*10+7) % K
        S.add(curr)
        ans += 1
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#n, m = map(int,input().split())
k = int(input())
#hl = list(map(int,input().split()))

s = len(str(k))

lst7 = []
for i in range(1,k+1):
    lst7.append(int('7'*i))

for i in range(len(lst7)):
    if lst7[i] % k == 0:
        print(i+1)
        exit()
print(-1)