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

def calculate(k):

    res = 1

    n = 7

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

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

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

    print(res)

calculate(K)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def calculate(k):

    res = 1

    n = 7

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

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

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

    print(res)

calculate(K)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

count = -1
n = 7
for i in range(K):
    if n % K == 0:
        count = i+1
        break
    n = int(str(n)+'7')

print(count)

Submission status: Time Limit Exceeded

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

else:
    c = 7
    count = 0
    while True :
        if c % K == 0:
            print(count+1)
            break

        c = int(str(c)+'7')
        count+=1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if K%2 == 0 or K%5 == 0:
  print("-1")
  exit(0)
for i in range(100000):
  if x % K == 0:
    print(count)
    exit(0)
  else:
    x = 10*x + 7
    count += 1
print("-1")

Submission status: Time Limit Exceeded

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

if K%2 == 0 or K%5 == 0:
  print("-1")
  exit()
for i in range(100000):
  if x % K == 0:
    print(count)
    exit(0)
  else:
    x = 10*x + 7
    count += 1
print("-1")

Submission status: Time Limit Exceeded

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

for i in range(100000):
  if x % K == 0:
    print(count)
    exit(0)
  else:
    x = 10*x + 7
    count += 1
print("-1")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def solve():
    K = int(input())
    a = 7%K
    i = 1
    Kset = set()
    Kset.add(a)
    while a!=0:
        a = (a*10+7)%K
        i += 1
        if a in Kset:
            print(-1)
            return
    print(i)


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
if k%2==0:
    print(-1)
else:
    charo=[7*(10**(i+1)//9) for i in range(k)]
    for cha in charo:
        if cha%k==0:
            print(len(str(cha)))
            break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

else:
    print(-1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

i = 1

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
m = 1

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

while True:
    a = int("7" * m) % K
    if a == 0:
        print(m)
        break
    else:
        m += 1

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

K=input()
i=len(K)
K=int(K)
if K%2==0:
	print(-1)
else:
  while True:
      s="7"*i
      if int(s)%K==0:
          print(i)
          break
      else:
          i=i+1

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
count = 1
number = 7
while count < 10000000:
    if number%K==0:
        print(count) 
        break
    else:
        number = number*10 + 7
        count += 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
l = 0
s = list()
for i in range(1,9000000):
    l = (l*10+7)%k
    if l == 0:
        print(i)
        exit()
    else:
        if s.count(l) == 0:
            s.append(l)
        else:
            print(-1)
            exit()
print(-1)
exit()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
l = 0
s = [False]*9000000
for i in range(1,9000000):
    l = (l*10+7)%k
    if l == 0:
        print(i)
        exit()
    else:
        if s[i] == True:
            print(-1)
            exit()
        else:
            s[i] = True
print(-1)
exit()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

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

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

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
cnt=0
ans=0
while cnt<1000001:
  cnt+=1
  ans=(ans*10)+7
  if ans%K==0:
    print(cnt)
    break
else:
  print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

count = 1
k = int(input())

for i in range(1000000):

    if k % 2 == 0:
        print(-1)
        break
    elif int(count*"7") % k == 0:
        print(count)
        break    
    count += 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

ans = 0
ai = 0

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

if K%2 == 0:
    print(-1)
else:
    ans = 0
    tmp = 0
    for i in range(K):
        tmp = tmp*10+7
        if tmp%K == 0:
            print(i+1)
            exit()
        else:
            continue
    print(-1)

Submission status: Time Limit Exceeded

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

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

print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
   print(-1)
   quit()
n = 7
nex = lambda x:x*10+7
for i in range(k):
   if n % k == 0:
      print(i+1)
      quit()
   n = nex(n)
print(-1)

Submission status: Time Limit Exceeded

Solution code:
def func(k):
    if k % 2 == 0 or k % 5 == 0:
        return -1
    else:
        if k % 7 == 0:
            l = 9 * k // 7
        else:
            l = 9 * k
        for i in range(1, 9000001):
            if 10**i % l == 1:
                return i

k = int(input())
print(func(k))

Submission status: Time Limit Exceeded

Solution code:
# ABC174A

def func(k):
    if k % 2 == 0 or k % 5 == 0:
        return -1
    else:
        s = 0
        for i in range(1, 1000000):
            s = 10 * s + 7
            if s % k == 0:
                return i
                break
        else:
            return -1

k = int(input())
print(func(k))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline

k=int(input())
mod=[]
seven=0
if k%2==0:
    print("-1")
    exit(0)
for i in range(10000000000000):
    seven=seven*10+7
    julia = seven%k
    mod.append(seven % k)
    if julia == 0:
        print(len(mod))
        exit(0)

Submission status: Time Limit Exceeded

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

cnt = 7
ans = 0
cnt2 = 0
i = 1

while ans == 0:
    if cnt%k == 0:
        ans = 1
        cnt2 += 1
    else:
        cnt2 += 1
        i *= 10
        cnt += 7*i

print(cnt2)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# 整数の入力
k = int(input())

x = 7%k
s=[]
i = 1
while(s.count(x) == 0):
    if x == 0:
        print(i)
        exit(0)
    s.append(x)
    x=(10*x+7)%k
    i += 1

print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

K = int(input())

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

tmp = 7
i = 1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#ABC174C


K = int(input())

nana = 7
ans = 0
count = 1

def calculation(K,ans,count,nana):
    while count != -1:
        if nana % K == 0:
            print(count)
            break
        nana = (nana*10 + 7)
        count += 1
        

if K % 2 == 0:
    print(-1)
else:
    calculation(K,ans,count,nana)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
K = int(input())

count =1
x=7

if K %2 ==0 or K %5 ==0:
    count = -1
else:
    while x %K !=0:
        count +=1
        x = x*10 +7
        #print(x,end =" ")
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
import time
start=time.time()
K=int(input())
ans=0
if K%2==0:
    print(-1)
else:
    if K%7==0:
        K//=7
    k=1
    kk=1
    end=time.time()
    while True:
        if (end-start)>1.5:
            ans=-1
            break
        kk*=10
        kk%=9*K
        if kk==1:
            ans=k
            break
        else:
            k+=1


    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import time
start=time.time()
K=int(input())
ans=0
if K%2==0:
    print(-1)
else:
    if K%7==0:
        K//=7
    k=1
    kk=1
    end=time.time()
    while True:
        if (end-start)>1.9:
            ans=-1
            break
        kk*=10
        kk%=9*K
        if kk==1:
            ans=k
            break
        else:
            k+=1


    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
K=int(input())
ans=0
if K%2==0:
    print(-1)
else:
    if K%7==0:
        K//=7
    k=1
    kk=1
    while True:
        kk*=10
        kk%=9*K
        if kk==1:
            ans=k
            break
        else:
            k+=1


    print(ans)

Submission status: Time Limit Exceeded

Solution code:
###############################################
#                                             #
#   author: raghav_0901 (Raghav Dalmia)       #
#   updated on: 04-08-2020,  3:41:14 pm IST   #
#                                             #
###############################################


from math import *

k = int(input())

if(k % 2 == 0 or k % 5 == 0):
    print(-1)
else:
    ans = 1
    num = 7
    while(ans < 100000):
        if(num % k == 0):
            print(ans)
            break
        num = (num * 10) + 7
        ans = ans + 1

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

seven = 7
ans = 0
for i in range(K):
    if K % 2 == 0 or K % 5 == 0:
        ans = -1
        break
    if seven % K == 0 :
        ans += i + 1
        break
    seven = seven * 10 + 7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

seven = 7
ans = 0
for i in range(K+1):
    if K % 2 == 0 or K % 5 == 0:
        ans = -1
        break
    if seven % K == 0 :
        ans += i + 1
        break
    seven = seven * 10 + 7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

# mod k で考える
mod=k

for i in range(1,10**6+1):
    if mod>7*int(str(1)*i):
        continue
    else:
        if mod==k:
            mod = 7 * int(str(1) * i) % mod
            if mod == 0:
                print(i)
                exit()
        else:
            mod= (mod*10+7)%k
            if mod==0:
                print(i)
                exit()

print(-1)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

# mod k で考える
mod=k
cnt=7
for i in range(1,k+2):
    if mod>cnt:
        cnt = cnt * 10 + 7
        continue
    else:
        mod = cnt % k
        if mod == 0:
            print(i)
            exit()
        cnt = cnt * 10 + 7

print(-1)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

# mod k で考える
mod=k

for i in range(1,k+2):
    if mod>7*int(str(1)*i):
        continue
    else:
        mod = 7 * int(str(1) * i) % k
        if mod == 0:
            print(i)
            exit()

print(-1)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

# mod k で考える
mod=k

for i in range(1,k+2):
    if mod>7*int(str(1)*i):
        continue
    else:
        if mod==k:
            mod = 7 * int(str(1) * i) % mod
            if mod == 0:
                print(i)
                exit()
        else:
            mod= (mod*10+7)%k
            if mod==0:
                print(i)
                exit()

print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
seven = ''
ans = 0
for i in range(10**6):
    seven = seven + '7'
    if(int(seven) % K == 0):
        ans = i + 1
        break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    K = int(input())
    if K%2 == 0:
        return -1
    ans = 1
    amari_reserve = 7%K
    amari = amari_reserve
    if amari_reserve == 0:
        return ans

    while True:
        ans += 1
        amari = (10*amari+7) % K
        if amari == 0:
            return ans
        if amari == amari_reserve:
            return -1


print(main())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
surps = dict()
num = 7
while 1:
    surp = num % k
    if surp == 0:
        print(len(str(num)))
        exit()
    else:
        if surp in surps:
            print(-1)
            exit()
        else:
            surps[surp] = 1
            num = num * 10 + 7

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

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

num=7
num%=k
ans=1

while k!=0:
  num=(10*num+7)%k+7

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = input()
k = int(k)
f = 0
if 1 <= k and k <= 1000000:
    for i in range(1, 1000000000):
        n = "7"*i
        n = int(n)
        if n%k == 0:
            print(i)
            f = 1
            break
if f == 0:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
n = 7
base_m = 7 % K

if base_m == 0:
    print(1)
    exit()
    
count = 1

def next_line(n):
    return n * 10 + 7

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

else:
    while(True):
        n = next_line(n)
        m = n % K
        count += 1

        if m == 0:
            print(count)
            break
        
        elif m == base_m:
            print(-1)
            break

Submission status: Time Limit Exceeded

Solution code:
# Hey, there Stalker!!!
# This Code was written by:
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
# ▒▒╔╗╔═══╦═══╗▒▒▒╔╗▒▒▒
# ▒╔╝║║╔═╗║╔═╗╠╗▒▒║║▒▒▒
# ▒╚╗║║║║║║║║║╠╬══╣║╔╗▒
# ▒▒║║║║║║║║║║╠╣║═╣╚╝╝▒
# ▒╔╝╚╣╚═╝║╚═╝║║║═╣╔╗╗▒
# ▒╚══╩═══╩═══╣╠══╩╝╚╝▒
# ▒▒▒▒▒▒▒▒▒▒▒╔╝║▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒╚═╝▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
#from functools import reduce

#mod=int(1e9+7)
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.stack_size(2**26)
"""fact=[1]
#for i in range(1,100001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*100001
#ifact[100000]=pow(fact[100000],mod-2,mod)
#for i in range(100000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod"""
#from collections import deque, defaultdict, Counter, OrderedDict
#from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
#from heapq import heappush, heappop, heapify, nlargest, nsmallest


# sys.setrecursionlimit(10**6) 
from sys import stdin, stdout
import bisect            #c++ upperbound
from bisect import bisect_left as bl              #c++ lowerbound bl(array,element)
from bisect import bisect_right as br             #c++ upperbound
import itertools
from collections import Counter

import collections
import math
import heapq
import re
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           #takes array as input
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
  
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l

def most_frequent(list):
    return max(set(list), key = list.count) 
def GCD(x,y):
    while(y):
        x, y = y, x % y
    return x

def ncr(n,r,p):                                              #To use this, Uncomment 19-25 
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t

def Convert(string): 
    li = list(string.split("")) 
    return li 

def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
prime=[]
q=[]
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j

#Implement heapq
#grades = [110, 25, 38, 49, 20, 95, 33, 87, 80, 90] 
#print(heapq.nlargest(3, grades)) #top 3 largest
#print(heapq.nsmallest(4, grades))
#Always make a variable of predefined function for  ex- fn=len
#n,k=map(int,input().split())
"""*******************************************************"""
def main():
    n=inin()
    if n&1==0:
        print(-1)
    else:
        cnt=1
        temp=0
        z=7
        while temp!=1:
            #print(cnt,int(cnt*str(7))) 
            if z%n==0:
                print(cnt)
                break
            else:
                cnt+=1
            z=10*z+7


"""*******************************************************"""
######## Python 2 and 3 footer by Pajenegod and c1729
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
 
import os, sys
from io import IOBase, BytesIO
 
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
if __name__== "__main__":
    main()
#threading.Thread(target=main).start()

Submission status: Time Limit Exceeded

Solution code:
# Hey, there Stalker!!!
# This Code was written by:
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
# ▒▒╔╗╔═══╦═══╗▒▒▒╔╗▒▒▒
# ▒╔╝║║╔═╗║╔═╗╠╗▒▒║║▒▒▒
# ▒╚╗║║║║║║║║║╠╬══╣║╔╗▒
# ▒▒║║║║║║║║║║╠╣║═╣╚╝╝▒
# ▒╔╝╚╣╚═╝║╚═╝║║║═╣╔╗╗▒
# ▒╚══╩═══╩═══╣╠══╩╝╚╝▒
# ▒▒▒▒▒▒▒▒▒▒▒╔╝║▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒╚═╝▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
#from functools import reduce

#mod=int(1e9+7)
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.stack_size(2**26)
"""fact=[1]
#for i in range(1,100001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*100001
#ifact[100000]=pow(fact[100000],mod-2,mod)
#for i in range(100000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod"""
#from collections import deque, defaultdict, Counter, OrderedDict
#from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
#from heapq import heappush, heappop, heapify, nlargest, nsmallest


# sys.setrecursionlimit(10**6) 
from sys import stdin, stdout
import bisect            #c++ upperbound
from bisect import bisect_left as bl              #c++ lowerbound bl(array,element)
from bisect import bisect_right as br             #c++ upperbound
import itertools
from collections import Counter

import collections
import math
import heapq
import re
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           #takes array as input
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
  
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l

def most_frequent(list):
    return max(set(list), key = list.count) 
def GCD(x,y):
    while(y):
        x, y = y, x % y
    return x

def ncr(n,r,p):                                              #To use this, Uncomment 19-25 
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t

def Convert(string): 
    li = list(string.split("")) 
    return li 

def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
prime=[]
q=[]
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j

#Implement heapq
#grades = [110, 25, 38, 49, 20, 95, 33, 87, 80, 90] 
#print(heapq.nlargest(3, grades)) #top 3 largest
#print(heapq.nsmallest(4, grades))
#Always make a variable of predefined function for  ex- fn=len
#n,k=map(int,input().split())
"""*******************************************************"""
def main():
    n=inin()
    if n&1==0:
        print(-1)
    else:
        cnt=1
        temp=0
        while temp!=1:
            #print(cnt,int(cnt*str(7)))
            if int(cnt*str(7))%n==0:
                print(cnt)
                break
            else:
                cnt+=1


"""*******************************************************"""
######## Python 2 and 3 footer by Pajenegod and c1729
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
 
import os, sys
from io import IOBase, BytesIO
 
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
if __name__== "__main__":
    main()
#threading.Thread(target=main).start()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
s = set()
x = 7
c = 1
while True:
  m = x % k
  
  
  if m == 0:
    print(c)
    break
  elif m in s:
    print(-1)
    break
    
  s.add(m)
  
  x = x*10 + 7
  c += 1

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

if K%2==0:
    print(-1)
    exit(0)
mod=7
for i in range(1,pow(10,6)):
    mod=mod%K
    if mod==0:
        print(i)
        exit(0)
    mod+=7*pow(10,i)
    #print(i,mod)


print(-1)

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)
elif k%7==0:
  l=9*k/7
  i=0
  while j==0:
    m=(m+s_1*(((s_2**i)%l-1)%l))%l
    if m==0:
      j==1
    else:
      i+=1
      ans+=1
  print(ans)
else:
  l=9*k
  i=0
  while j==0:
    m=(m+s_1*(((s_2**i)%l-1)%l))%l
    if m==0:
      j==1
    else:
      i+=1
      ans+=1
  print(ans)