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())
i=1
seven='7'
if k%2==0:
    print(-1)
else:
    while int(seven)%k!=0:
        seven+='7'
        i+=1
    print(i)

Submission status: Time Limit Exceeded

Solution code:
param_a = int(input())

for i in range(1000000):
    param_str = '7'*(i+1)
    param_int = int(param_str)
    
    if param_int % param_a == 0:
        param_answer = i+1
        break

try:
    print(param_answer)
except:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
A = 7
Flag = False
for T in range(1,K+1):
    if A%K==0:
        Flag = True
        break
    else:
        A = 10*A+7
print(['-1',T][Flag])

Submission status: Time Limit Exceeded

Solution code:
k = input()

a = '7'
if len(k)!=1:
    for i in range(len(k)-1):
        a += '7'

if int(k) % 2 == 0:
    print(-1)
else:
    for i in range(10 ** 6):
        if int(a) % int(k) == 0:
            print(len(a))
            exit()
        else:
            a += '7'

Submission status: Time Limit Exceeded

Solution code:
def main():

    K = int(input())
    # N, D = map(int, input().split())
    # A = [int(i) for i in input().split()]

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

    ans = 1
    N = 7
    while 1:
        # print(f"{N = }")
        N %= K
        if not N:
            break
        N = N * 10 + 7
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

s=7

cnt=1
m=0
while(1):
  t=s%k
  if t==0:
    print(cnt)
    break
  else:
    s=t*10 + 7

  if cnt==1:
    m=t

  elif m==t:
    print("-1")
    break
  cnt+=1

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
""" C
    https://atcoder.jp/contests/abc173/tasks/abc173_c
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def _pattern(N):
    if N > 1:
        pa = _pattern(N-1)
        return [[0] + p for p in pa] + [[1] + p for p in pa]
    else:
        return [[0], [1]]

def main(K):
    count = 1
    result = 7 % K
    past_result = [result]
    while True:
        if result == 0:
            break
        result = (result * 10 + 7) % K
        if result in past_result:
            return -1
        past_result.append(result)
        count += 1

    return count

if __name__ == "__main__":
    _K = readInteger()

    print(main(_K))

Submission status: Time Limit Exceeded

Solution code:
from math import *
n=int(input())
if n%2==0:
    print(-1)
else:
    s='7'
    m=int(s)
    k=m%n
    while k!=0:
        s=s+'7'
        m=int(s)
        k=m%n
        if k==0:
            break
    print(len(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())


def fun(k):
    i = 7
    count = 1
    if k % 2 == 0:
        return -1
    while True:
        if i % k == 0:
            return count
        else:
            i = i*10+7
            count += 1
    return -1


print(fun(k))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
now = 7
cnt = 1
no = False
while True:
  if now % k == 0:
    break
  cnt += 1
  now = now * 10 + 7
  if cnt >1000000 :
    no = True

if no :
  print(-1)
else :
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():

    k = int(input())
    if k % 2 == 0:
        print('-1')
    else:
        for i in range(1, k + 1):
            target = int('1' * i) * 7
            if target % k == 0:
                print(i)
                break

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def main():
    #an+1=(10~n)*7+an
    K=int(input())
    if K%2==0:
        print(-1)
        sys.exit()
    n=0
    a=7
    while True:
        if a%K==0:
            break
        n+=1
        a=(a+(pow(10,n,K)*7))%K
    print(n+1)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))
ks = str(k)

n = len(ks)

if n-1 != 0:
    sevn = "7"*(n-1)
else:
    sevn = "7"
    n = 2
#print(sevn)


for i in range(n-1,n-1+10**5+1):
    tmp = int(sevn)
    if tmp%k==0:
        print(i)
        exit()
    sevn += "7"
    #i += 1

print(-1)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
k = int(input())
if k % 2 < 1 or k % 5 < 0:
    print(-1)
else:
    c = len(str(k))
    mod = int("7" * c) % k
    while mod > 0:
        mod += pow(10, c, k) * 7
        mod %= k
        c += 1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
now = 7
cnt = 1
no = False
while True:
  if now % k == 0:
    break
  cnt += 1
  now = now * 10 + 7
  if cnt >5000000 :
    no = True

if no :
  print(-1)
else :
  print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
""" C
    https://atcoder.jp/contests/abc173/tasks/abc173_c
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])

def _pattern(N):
    if N > 1:
        pa = _pattern(N-1)
        return [[0] + p for p in pa] + [[1] + p for p in pa]
    else:
        return [[0], [1]]

def main(K):
    count = 1
    result = 7 % K
    while True:
        if result == 0:
            break
        result_ = result
        result = (result * 10 + 7) % K
        if result_ == result:
            return -1
        count += 1

    return count

if __name__ == "__main__":
    _K = readInteger()

    print(main(_K))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
# N, D = [int(i) for i in input().split()]
def pow_(x, n):
  if n == 0:
    return 1

  k = 1
  while n > 1:
    if n % 2 != 0:
      k *= x
    x *= x
    n //= 2

  return k * x

K = int(input())
count = 0
for i in range(1, 10**6):
  count += 1
  if (7 * (pow_(10, i) - 1) // 9) % K == 0:
    print(count)
    break
else:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
a_list=[]
amari=0
count=0
flag=False
if a%2==0 :
  flag=True
else :

  while(True) :
    k=(amari*10+7)%a
    if k==0 :
      count+=1
      break
    else :
      count+=1
      amari=k



if flag :
  print('-1')
else :
  print(count)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
if k%2==0:
    print(-1)
else:
    n=7
    cnt=1
    while n%k!=0:
        n=(n*10+7)%k
        cnt+=1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
c=1
m='7'
if k%2==0:
    print(-1)
else:
    while True:
        if c > 1:
            m=m+'7'
        if int(m)%k==0:
            print(c)
            break
        c+=1

Submission status: Time Limit Exceeded

Solution code:
import sys
k=int(input())
A=[0]*k
C=[7%k]
A[7%k]=1
if 7%k==0:
    print(1)
    sys.exit()
while True:
    now=(C[-1]*10+7)%k
    C.append(now)
    if now==0:
        print(len(C))
        break
    if A[now]:
        print(-1)
        break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0:
        count += 1
        rem += 7 * pow(10, count-1, mod=K) % K
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
if int(n%2)==0:
    print('-1')
else:
    a=['7']
    count=0
    while True:
        if int(int(''.join(a))%n)==0:
            count+=1
            break
        else:
            a.append('7')
            count+=1
    print(count)

Submission status: Time Limit Exceeded

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

else:
    for i in range(1000000):
        seven += "7"
        if (int(seven) % k == 0):
            print(i+1)
            break

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import time
    start=time.time()
    K=int(sys.stdin.readline())
    if K%2==0:
        print(-1)
        return

    L=[7%K]
    L2=[7%K]
    if L[0]==0:
        print(1)
        return

    idx=0
    while True:
        L2.append((L2[idx]*10)%K)
        L.append((L[idx]+L2[idx+1])%K)
        if L[-1]==0:
            print(len(L))
            return
        idx+=1

        if start-time.time()>=1.2:
            print(-1)
            return
main()

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
L=[0]*K
k=0
x=0
while(1):
    x=x+7*(10**k)
    q=(x % K)
    if(q==0):
        print(k+1)
        break
    if(L[q]==1):
        print(-1)
        break
    else:
        L[q]=1
    k+=1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import time
    start=time.time()
    K=int(sys.stdin.readline())
    if K%2==0:
        print(-1)
        return

    L=[7%K]
    L2=[7%K]
    if L[0]==0:
        print(1)
        return

    idx=0
    while True:
        L2.append((L2[idx]*10)%K)
        L.append((L[idx]+L2[idx+1])%K)
        if L[-1]==0:
            print(len(L))
            return
        idx+=1

        if start-time.time()>=1.8:
            print(-1)
            return
main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
i = 1
ans = 1
while True:
    if n % 2 == 0:
        print("-1")
        break
    a = i * 7
    if a % n == 0:
        print(ans)
        break
    ans += 1
    i = i * 10 + 1

Submission status: Time Limit Exceeded

Solution code:
import sys

K = int(input())

flag = 0
count = 0
num = 7

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

while flag == 0:
    count += 1
    if num % K == 0:
        print(count)
        flag = 1
    else:
        num = num % K
        num = num * 10 + 7

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    K = int(input())
    left = 7 % K
    right = 1 % K
    next_add = 1
    if not K % 2:
        print(-1)
        return None
    ans = 1
    dic = {}
    while True:
        if not left * right % K:
            print(ans)
            return None
        else:
            dic
            next_add = next_add * 10 % K
            right = (right + next_add) % K
            ans += 1
            if right == 1:
                print(-1)
                return

if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
count = 0
if k%2==0:
    print(-1)
else:
    while 1:
        count+=1
        # print(count)
        t = "7"*count
        if int(t)%k==0:
            print(count)
            break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

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

def main(kwargs):
    k = kwargs["k"]
    res = 0
    p = 7
    rs = 0

    while True:
        res += 1
        r = p % k
        rs += r
        if rs % k == 0:
            break
        if r == 0:
            res = -1
            break
        p = r * 10


    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["k"] = [int(i) for i in cin][0]

    cout = main(kwargs)
    print(cout)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
num=7
ans=1
p=0
while num%k!=0 and p<10**6:
    num=num*10+7
    ans+=1
    p+=1
if p==10**6:
    print("-1")
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

if k % 2 == 0:
    print(-1)
else:
    ans = 1
    num = 7
    while True:
        if int(num) % k == 0:
            print(ans)
            break
        else:
            ans += 1
            num += 7 * pow(10, ans - 1, k)
            num %= k

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
a_list=[]
amari=0
count=0
flag=False
while(True) :
  k=(amari*10+7)%a
  if k  in a_list :
    flag=True
    break
  elif k==0 :
    count+=1
    break
  else :
    count+=1
    amari=k
    a_list.append(amari)


if flag :
  print('-1')
else :
  print(count)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
for i in range(1,1000000):
    S="7"*i
    #print(S)
    S=int(S)
    if S%999983==0:
        print(S,i)

Submission status: Time Limit Exceeded

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

k = int(input())
n = 7
ans = -1

for i in range(10**6): #注意
  if n % k  == 0:
    ans = i+1
    break
  else:
    n =  n*10 + 7
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    i = 7
    while True:
        if i % k == 0:
            print(len(str(i)))
            break
        i *= 10
        i += 7

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
K = int(input())
if K % 2 == 0:
    print(-1)
else:
    i = 0
    num = 7
    while 1:
        if num % K == 0:
            print(i + 1)
            break
        i += 1
        num = num + 7 * (10 ** i)

Submission status: Time Limit Exceeded

Solution code:
K = int(input().strip())

if K%2 == 0:
  print(-1)
else:
  d = len(str(K))
  tgt = int('7'*d)
  while tgt%K != 0:
    d += 1
    tgt = int('7'*d)
  print(d)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    K=int(sys.stdin.readline())
    if K%2==0:
        print(-1)
        return

    L=[7%K]
    L2=[7%K]
    if L[0]==0:
        print(1)
        return

    idx=0
    while True:
        L2.append((L2[idx]*10)%K)
        L.append((L[idx]+L2[idx+1])%K)
        if L[-1]==0:
            print(len(L))
            return
        idx+=1


main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
k = int(input())
if k % 2 < 1 or k % 5 < 0:
    print(-1)
else:
    c = 1
    mod = 7 % k
    while mod > 0:
        mod += pow(10, c, k)*7
        mod %= k
        c += 1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    K = int(input())
    left = 7 % K
    right = 1 % K
    next_add = 1
    if not K % 2:
        print(-1)
        return None
    ans = 1
    while True:
        if not left * right % K:
            print(ans)
            return None
        else:
            next_add = next_add * 10 % K
            right = (right + next_add) % K
            ans += 1

if __name__ == "__main__":
    run()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
N = 7 % K
i = 1
modl = [N]
ret = -1
while True:
  if N == 0:
    ret = i
    break
  N = ((N * 10) % K + 7 )% K
  if N in modl:
    break
  modl.append(N)
  i += 1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())


k9=k*9
l=10
for n in range(1,k9+5):
    if l*7%k9==7%k9:
        print(n)
        break
    l=l*10%k9
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

for i in range(1, 1000000):
    nana = int('7' * i)
    
    if nana % n == 0:
        print(i)
        break
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
inp = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    k = int(input())
    a = 7
    c = 1
    b = 7
    if k == 2 or k == 5:
        print(-1)
        exit()
    while True:
        if a%k== 0:
            print(c)
            break
        else:
            b = (b*10)%k
            a = b+a
            a = a %k
            c += 1
            if c > k:
                print(-1)

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#from math import *
from collections import *
from random import *
from bisect import *
import sys
input=sys.stdin.readline
def lis():
    return list(map(int,input().split()))
def ma():
    return map(int,input().split())
def inp():
    return int(input())
n=inp()
if(n%2==0):
    print(-1)
    exit(0)
co=1
while(1):
    r=int('7'*co)
    if(co>n):
        co=-1
        break
    if(r%n==0):
        break
    co+=1
print(co)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
	K = int(input())
	dls = []
	d = 7 % K
	dls.append(d)
	c = 1
	if K % 2 == 0:
		c = -1
		d = 0
	while(d != 0):
		d = (d*10 + 7)%K
		if d in dls:
			c = -1
			break
		else:
			c += 1
	print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
ama = -1
cnt = 1
x = 7
while ama!=0:
    if k % 2 == 0:
        print('-1')
        ama = 0
        break

    if x % k == 0:
        ama = 0
        print(cnt)
        break
        
    x = x*10 + 7
    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

if K % 2 == 0:
    print(-1)
    exit()
rest = 7 % K
x = rest
ans = 1
while rest:
    ans += 1
    x = x*10 % K
    rest = (rest + x) % K
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    k = int(input())
    a = 7
    c = 1
    b = 7
    if k == 2 or k == 5:
        print(-1)
        exit()
    while True:
        if a%k== 0:
            print(c)
            break
        else:
            b = (b*10)%k
            a = b+a
            a = a %k
            c += 1

main()

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

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

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    K = int(input())

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

    tmp = 7
    ans = 1
    while tmp % K != 0:
        tmp = (tmp % K) * 10 + 7
        ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    k = int(input())
    tmp = 7
    mul = 1
    p = 1
    while p < 10**7 and tmp % k != 0:
        mul *= 10
        tmp += 7 * mul
        mul %= k
        tmp %= k
        p += 1
    if tmp % k == 0:
        print(p)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict 
import sys
import math 

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

s = ""

count = 0

while(True):
  s += "7"
  nana = int(s)
  count += 1
  if(nana % k == 0):
    print(count)
    break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

if N%2 == 0 or N == 5:
    print(-1)
    quit()
    
temp = 7%N
ans = 1
while temp != 0:
    temp = (temp*10+7)%N
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

for i in range(1, 10**5):
    n = "7" * i
    n = int(n)
    if n % K == 0:
        print(i)
        exit()
print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
cnt = 1
ans = 7
ans %= k
flags = [False] * k
flags[ans] = True
while ans != 0:
    ans += 7*pow(10,cnt,k)
    cnt += 1
    ans %= k
    if flags[ans]:
        cnt = -1
        break
    flags[ans] = True

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

Submission status: Time Limit Exceeded

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=7%K
mod_k=7%K
ans=1
while(1):
    if(mod==0):
        print(ans)
        sys.exit(0)
    mod_k=(mod_k*10)%K   
    if(mod_k==0):
        print(-1)
        sys.exit(0)
    mod=(mod+mod_k)%K
    ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  k = int(input())
  num = 7 % k
  first = num
  ans = 1
  while num != 0:
    ans += 1
    num = (num*10 + 7)%k
    if num == first:
      ans = -1
      break
  print(ans)
    
    
if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
sevens = []

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    for n in range(1,10**6):
        sevens.append("7")
        int_sevens = int("".join(sevens))
        if int_sevens % K == 0:
            print(n)
            break
        if n == 10**6:
            print(-1)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

k = INT()
num = 0
for i in range(1, 10 ** 6 + 100):
    num *= 10
    num += 7
    if num % k == 0:
        print(i)
        exit()
print(-1)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
n=len(str(K))
N=int("7"*n)
if K%2==0:
    print(-1)
else:
    while N%K!=0:
        n+=1
        N=N*10+7
        N%=K
    print(n)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

a = 0
flag = False
for i in range(1000010):
    a = 10 * a + 7
    if a % k == 0:
        flag = True
        break
if flag:
    print(i+1)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
if n%2==0: print(-1)
else:
    i=1
    x=7
    while x%n!=0:
        x*=10
        x+=7
        i+=1
    print(i)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

amari = 0

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

print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))

sevn = "7"
i = 1
for i in range(1,10**6+1):
    tmp = int(sevn)
    if tmp%k==0:
        print(i)
        exit()
    sevn += "7"
    #i += 1

print(-1)