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

Submission status: Time Limit Exceeded

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K = ii()

    ret = [7]
    for i in range(1, K + 1):
        ret.append(ret[i-1]* 10 + 7)

    for i in range(K + 1):
        if ret[i] % K == 0:
            print(i + 1)
            exit()
    else:
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
def last2digit(a):
    sevens = True
    i = 0
    while i < 2 and a > 0:
        #print (a, i)
        if a % 10 != 7:
            sevens = False
        a //= 10
        i += 1
    return sevens
impossible = True
for i in range(20):
    a = k * i
    if last2digit(a):
        impossible = False

if k % 2 == 0 or impossible:
    print(-1)
else:
    ans = 1
    seven = 7
    while seven % k != 0:
        seven = seven * 10 + 7
        ans += 1
        if ans >= 999982:
            print (ans, seven)
            break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__=='__main__':
    t = int(input());
    cnt = 0;
    num = 0;
    pos = False;
    for i in range(0,9999999):
        num*=10;
        num+=7;
        cnt+=1;
        if(num%t==0):
            pos = True;
            break;
        #print(cnt);
    if(pos):
        print(cnt);
    else:
        print("-1");

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
g = -1
for i in range(1, int(1e6)+1):
	if int("7"*i)%n == 0: g = i;break
print(g)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
n=7
ans=0

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

Submission status: Time Limit Exceeded

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

if t==0:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans=1
seven="7"
orignal="7"
if n%2==0:
    print(-1)
else:
    while True:
        int_seven=int(orignal)
        if int_seven%n==0:
            print(ans)
            break
        else:
            ans+=1
            orignal+=seven

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
firsta = 7 % K
seconda = 77 % K
if firsta == 0:
    print(1)
elif firsta == seconda:
    print(-1)
else:
    ans = 2
    preva = seconda
    while preva != firsta and preva != 0:
        preva = ((preva*10)+7) % K
        ans += 1
        if preva == firsta:
            ans = -1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
firsta = 7 % K
if firsta == 0:
    print(1)
elif firsta == 77 % K:
    print(-1)
else:
    ans = 2
    preva = 77 % K
    while preva != firsta and preva != 0:
        preva = ((preva*10)+7) % K
        ans += 1
        if preva == firsta:
            ans = -1
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
x = 7%k
s = set()
i = 1
while list(s).count(x) == 0:
  if x == 0:
    print(i)
    exit()
  s.add(x)
  x = (x*10+7)%k
  i += 1
print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

now = 0
count = 0
while True:
    now = now * 10 + 7
    count += 1
    if now % K == 0:
        print(count)
        exit()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
if k % 2 == 0:
    print(-1)
else:
    mod = 7 % k
    counter = 1
    memo = 1
    while mod != 0:
        memo = ((memo % k) * (10 % k)) % k
        mod = (mod + 7 * memo) % k
        counter += 1
        if mod == 0:
            break
    print(counter)

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 = 10 * t + 7

else :
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def counter(k):
  count = 1
  n = 0
  if k % 2 == 0 or k % 5 == 0:
    print(-1)
  while 1:
    n = (n * 10 + 7) % k  
    if n == 0:
      break 
    count += 1
  print(count)
      
if __name__ == '__main__':
  k = int(input())
  counter(k)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
count = len(str(K))
n = 0
for i in range(count):
    n += 7*10**i
while True:
    if K % 2 == 0 or K % 5 == 0:
        count = -1
        break
    if n % K == 0:
        break
    n += 7*10**count
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
count = len(str(K))
n = 0
for i in range(count):
    n += 7*10**i
while True:
    if K % 2 == 0:
        count = -1
        break
    if n % K == 0:
        break
    n += 7*10**count
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    k = int(input())
    seven = 7
    cnt = 0
    if k%2==0:
        print(-1)
        return 
    while seven != 0:
        seven %= k
        cnt += 1 
        if seven != 0:
            seven = seven * 10 + 7
    print(cnt)
    return

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
K = int(input())
s = '7'
if K % 2 == 0:
    print(-1)

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

        i = i + 1

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
ans = -1
if K > 10**6:
    ans = -1
elif K % 2 == 0:
    ans = -1
else:
    str_num = '7'*len(str(K))
    while len(str_num) <= 10**6:
        num = int(str_num)
        if num % K == 0:
            ans = len(str_num)
            break
        str_num += '7'
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
k = int(stdin.readline().rstrip())
num = 7
flag = 0
for i in range(1, k + 1):
    if num % k == 0:
        flag = 1
        break
    num = num * 10 + 7
if flag == 1:
    print(i)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

d = int(7)
count =1


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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
number = 7
total = 1
while number % K != 0:
    number = number * 10 + 7
    total += 1  
print(total)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
i='7'
if K%2==0 or K%5==0:
    print('-1')
else:
    for d in range(K):
        if int(i)%K==0:
            print(len(str(i)))
            break
        else:
            i+='7'

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc174/tasks/abc174_c
K= int(input(" "))

if K%2==0 or K%5==0:
    print(-1)
elif K==1 or K==7:
    print(1)
else:
    B = 7
    i = 1
    while 1:
        if B%K==0:
            print(i)
            break
        else:
            B = 10 * B + 7
            i = i + 1

Submission status: Time Limit Exceeded

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

K= int(input(" "))

B= 7

if K%2==0 or K%5==0:
    print(-1)
elif K==1 or K==7:
    print(1)
else:
    i = 1
    while 1:
        i= i+1
        B = 10*B + 7
        if B%K==0:
            print(i)
            break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

K=int(input())


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


i=1

while True:
	if 7*int("1"*i)%K==0:
		exit(print(i))
	i+=1
	if i>1e+15:
		exit(print(-1))

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

i=1

while True:
	if 7*int("1"*i)%K==0:
		exit(print(i))
	i+=1

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
m=''
if k%2!=0:
    for _ in range(len(str(k))):
        m+='7'
    while int(m)%k!=0:
        m+='7'
    print(len(m))
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

K = int(input())
flg = -1

@lru_cache(maxsize = None)
def recur(n):
    if n == 1:
        return 7
    else:
        return recur(n-1) * 10 + 7
    
def mod(n):
    return recur(n) % K
    
a = [mod(n) for n in range(1, K + 1)]

for i in range(0, K):
    if a[i] == 0:
        print(i + 1)
        flg = 0
        break

if flg == -1:
    print(flg)
    
recur.cache_clear()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    K_1 = str(K)[len(str(K)) - 1]

    if K % 2 == 0 or K_1 == "4" or K_1 == "5" or K_1 == "6" or K_1 == "8":
        print("-1")
    else:
        start_num = 0
        if K_1 == "1" :
            start_num = 7
        elif K_1 == "3":
            start_num = 9
        elif  K_1 == "7":
            start_num = 1
        elif K_1 == "9":
            start_num = 3

        while True:
            if len(str(K * start_num)) == str(K * start_num).count("7"):
                print(str(K * start_num).count("7"))
                break
            start_num = start_num + 10
main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
if x % 2 == 0:
    print(-1)
    exit()
s = 7
cnt = 1
while True:
    if s % x == 0:
        print(cnt)
        break
    s = s * 10 + 7
    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

num = 0
cnt = 1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
j = 7
i = 1
# f_inf = float('inf')
if k % 2 == 0:
    print("-1")
    exit()
# for i in range(int(f_inf)):
#   j = j * i + j
#   if j % k == 0:
#     print(i)
#   else:
#       j = j * i + j

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

Alpha = 0
i=0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

Alpha = 0
i=0

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

Submission status: Time Limit Exceeded

Solution code:

K = int(input())
A = 7 % K 

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
if k%2==0:
    ans=-1
else:
    cnt=1
    cur=7
    while True:
        if cur%k==0:
            ans=cnt
            break
        if cnt>k:
            ans=-1
            break
        cnt+=1
        cur=(7*(10**cnt))//9
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

k = int(input())

a = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
a = 7
c = 0

for i in range(10**8):
  c = c + 1
  if k%2 == 0:
  
    break
  if k%5== 0:
    break
    
  if a%k == 0:
    print(c)
    break
  b = str(a)+'7'
  a = int(b)
if a%k != 0:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
a = 7
c = 0

while True:
  c = c + 1
  if k%2 == 0:
  
    break
  if k%5== 0:
    break
    
  if a%k == 0:
    print(c)
    break
  b = str(a)+'7'
  a = int(b)
if a%k != 0:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
a = 7
c = 0
while True:
  c = c + 1
  if a%k == 0:
    print(c)
    break
  b = str(a)+'7'
  a = int(b)
if a%k != 0:
  print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

ans = -1
num7 = 7
if K%2 != 0:
    for i in range(100000):
        if (num7 % K) == 0:
            ans = i+1
            break
        else:
            num7 = num7*10+7
            i+=1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

ans = -1
num7 = 7;

for i in range(100000):
    if (num7 % K) == 0:
        ans = i+1
        break
    else:
        num7 = num7*10+7
        i+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())


i = 1
s = '7'


while True:
    if k % 2 == 0:
        print('-1')
        exit()
    if int(s) % k == 0:
        print(str(i))
        exit()
    s += '7'
    i += 1

Submission status: Time Limit Exceeded

Solution code:
n = int(input().rstrip())

def calc(target):
    excess = set()
    result = 0
    count = 0
    if target % 2 == 0:
        return -1
        
    while True:
        count += 1
        result = (result * 10 + 7) % target
        excess.add(result)
        if result == 0:
            break
    
    return count
    
print(calc(n))

Submission status: Time Limit Exceeded

Solution code:
def main():
    k = int(input())
    alt_7 = 7
    mod_k = 7
    count = 1
    while alt_7 % k != 0:
        mod_k = mod_k * 10 % k
        if mod_k == 0:
            print(-1)
            return
        alt_7 += mod_k
        count += 1
    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
target = int(input())

x = 7
i = 1

while True:
  if x % target == 0:
    print(i)
    break
  else:
    x = x*10 + 7
    i += 1

Submission status: Time Limit Exceeded

Solution code:
target = int(input())

i = 1
if target % 2 == 0:
  print("-1")

while True:
  temp = "7" * i
  if int(temp) % target == 0:
    print(i)
  else:
    i += 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def make_7(p):
  x = ""
  for i in range(p):
    x = x + "7"
  return int(x)

K = int(input().rstrip())

if K%2 == 0:
  print('-1')
  
else:
  i = 1
  while True:
    x = make_7(i)
    if x%K == 0:
      print(i)
      break
    else:
      i += 1

Submission status: Time Limit Exceeded

Solution code:
import sys
K=int(input())
i=1
K=9*K

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def test_case(k):
    ans,cnt = 7,1
    
    if k % 2 == 0 or k % 5 == 0:
        return -1
    
    if k == 1 or k == 7:
        return 1
    
    while (1):
        mod = (ans * 10 + 7) % k
        cnt += 1
        ans = ans * 10 + 7
        
        if mod == 0:
            return cnt
        
print(test_case(k))

Submission status: Time Limit Exceeded

Solution code:

def nthNum(nMinusOneNum):
    return nMinusOneNum*10 + 7

K = int(input())

crawler = 7
i = 0

if (K % 2 ==0):
    print(-1)
else:
    while True:
        if crawler%K == 0:
            print(i + 1)
            break
        temp = nthNum(crawler)
        crawler = temp;
        i += 1

Submission status: Time Limit Exceeded

Solution code:
def solve():
    K = int(input())
    K_one = K % 10
    cnt = 0

    carry = 0
    carry_one = carry % 10

    while True:
        is_ok = False
        for i in range(0,9+1):
            if (i * K_one + carry_one) % 10 == 7:
                is_ok = True
                cnt += 1
                carry = (K * i + carry) // 10
                carry_one = carry % 10
                break
        
        if not is_ok:
            print(-1)
            return
        
        carry_str = str(carry)
        if carry_str.count('7') == len(carry_str):
            print(len(carry_str) + cnt)
            return
    
if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
ans = 1
x = 7
z = 0

if K % 2 == 0:
    print('-1')
else:
    while z == 0:
        if x % K == 0:
            print(ans)
            z += 1
        else:
            x += 10 ** ans * 7
            ans += 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import *
from math import gcd

k = int(input())
if gcd(k, 10) == 1:
    i = 0
    while True:
        i += 1
        rep = (10 ** i // 9) * 7
        if rep % k == 0:
            print(i)
            break
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
import math as mt

K = int(input())
remain = {}

if K%2 == 0:
    print("-1")
else:
    x = 7
    while(True):
        a = str(x % K)
        if a == "0":
            print(len(str(x)))
            break
        elif a in remain.keys():
            print("-1")
            break
        else:
            remain[a] = 1
        
        x = x*10 + 7
        # print("remainder: "+a+" x: "+str(x))

Submission status: Time Limit Exceeded

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

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_l=[0]*(K*10)
mod_l[0]=7%K
mod_k=7%K
ans=1
for i in range(10*K-1):
    if(mod_l[i]==0):
        print(ans)
        sys.exit(0)
    mod_k=(mod_k*10)%K  
    if(mod_k==0):
        print("-1")
        sys.exit(0)
    mod_l[i+1]=(mod_l[i]+mod_k)%K
    ans+=1

print("-1")