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

seven = 7


if K%2==0:
  print("-1")
elif K%5==0:
  print("-1")
else:

  for i in range(K):
    if seven%K==0:
      print(len(str(seven)))
      break
    else:
      seven = seven*10+7

Submission status: Time Limit Exceeded

Solution code:

def solve():
	n=input()
	s='7'*len(n)
	flag=1
	i=len(n)
	if(int(n)%2==0):
		print(-1)
		return
	while(flag):
		if(int(s)%int(n)==0):
			flag=0
		else:
			i+=1
			s='7'*i
	print(len(s))
if __name__ == "__main__":
	#code goes below
	# for _ in range(int(input())):
	solve()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
f = False

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

else:
  n = 0
  for j in range(1000000000):
    n += (10 ** j) * 7
    if n % k == 0:
      print(j+1)
      break

Submission status: Time Limit Exceeded

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

INF = 10**9+7

if __name__ == "__main__":
    k = int(input())
    if k%2 == 0:
        print(-1)
        sys.exit()
    a = 7
    p = len(str(k)) + 1
    for i in range(p+10**5):
        if a%k == 0:
            print(i+1)
            sys.exit()
        a*=10
        a+=7
    print(k-1)

Submission status: Time Limit Exceeded

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

    amari_sum = 0
    i = 1
    amari = 7 % K
    amari_sum += amari
    if amari == 0:
        return i

    while True:
        i += 1
        amari = (amari*10) % K
        amari_sum += amari
        if amari_sum % K == 0:
            return i
        #else:
            #amari_sum %= K

print(main())

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

n=0
ans = -1

for i in range(1, k+1):
  n = n * 10 +7
  if n % k == 0:
    ans = i
    break

print(ans)

Submission status: Time Limit Exceeded

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

S=""
count=-1

for i in range(K):
  S += "7"
  M = int(S)
  if( M%K == 0):
    count = i+1
    break

print(count)

Submission status: Time Limit Exceeded

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

count = 0
key_number = 7
base_number = 0
if k % 2 == 0:
    print("-1")
if k % 2 == 1:
    while True:
        base_number += key_number * (10 ** count)
        count +=1
        q, mod = divmod(base_number, k)
        if mod == 0:
            print(count)
            break

Submission status: Time Limit Exceeded

Solution code:
import math
k = int(input())
count = 0
before = 0

while True:
    if k % 2 == 0:
        print(-1)
        break
    seven = 10**count*7 + before
    #print(seven)
    if seven%k == 0:
        print(count+1)
        break
    else:
        before = seven
        count +=1
        #print(count)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
if k%10 in [2,4,5,6,8,0]:
  print(-1)
  exit()

for i in range(1,50000):
  tmp=7*(10**i-1)//9
  if tmp%k==0:
    print(i)
    exit()
print(k-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
i = 0
a = ""

if(K%2==0):
    print(-1)
else:
    while True:
        i = i + 1
        a = a + "1"
        A = int(a)*7
        if(A%K==0):
            print(i)
            exit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

a = 0
ans = -1

for i in range(K):

    a += 7 * 10**i

    if a % K == 0:
        ans = i+1
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print('-1')
else:
    num = 0
    for i in range(10**7):
        num = num * 10 + 7
        if K > num:
            continue
        elif num % K == 0:
            print(i+1)
            break

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
if k%2==0:exit(print(-1))
ans=0
x=k
for i in range(10**9):
  while x%10!=7:x+=k
  x//=10
  if x==0:exit(print(i+1))

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

x=1
c=7

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

Submission status: Time Limit Exceeded

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

i = 1
A = 7 % K
while A != 0:
    A = (10 * A + 7) % K
    i += 1
print(i)

Submission status: Time Limit Exceeded

Solution code:

def next7(s):
    return s * 10 + 7


def submit():
    k = int(input())

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

    s = 7
    ans = 1
    while s % k:
        s = next7(s)
        ans += 1

    print(ans)


submit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

count = 0
ans = 1

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

Submission status: Time Limit Exceeded

Solution code:
import sys
K = input()
if K[-1] == '2' or K[-1] == '4' or K[-1] == '5' or K[-1] == '6' or K[-1] == '8' or K[-1] == '0':
    print(-1)
    sys.exit()
if K[-1] == '1':
    i = 7
elif K[-1] == '3':
    i = 9
elif K[-1] == '7':
    i = 1
elif K[-1] == '9':
    i = 3
K = int(K)
while True:
    N = K * i
    n = set(str(N))
    if n == {'7'}:
        N = str(N)
        print(len(N))
        sys.exit()
    i += 10

Submission status: Time Limit Exceeded

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

    while True:
        i += 1
        amari = (amari*10) % K
        amari_sum += amari
        if amari_sum % K == 0:
            return i
        else:
            amari_sum %= K

print(main())

Submission status: Time Limit Exceeded

Solution code:
K = float(input())

seven = ['7']

i = 0

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

    if float(seven[0]) % K == 0:
        print(i+1)
        break

    seven.append(seven[0] + '7') 
    del seven[0]
    i += 1

Submission status: Time Limit Exceeded

Solution code:
k = input()
o = True
p = list()
lock = 0
while o == True:
    p.append('7')
    j =''
    j = j.join(p)
   
    if int(j)%int(k) == 0:
        o = False
    
    if k[-1] == '0' or k[-1] == '2' or k[-1] == '4' or k[-1] == '5' or k[-1] == '6' or k[-1] == '8':
        lock = 1
        o = False
        
if lock == 1:
    print('-1')
else:
    print(len(j))

Submission status: Time Limit Exceeded

Solution code:
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    
def solve():
    n = inp()
    q = ""
    w = -1
    for i in range(n):
        q += "7"
        if int(q) % n == 0:
            w = i + 1
            break
    print(w)
    
    
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)

def counter_elements(a):
    q = dict()
    for i in range(len(a)):
        if a[i] not in q:
            q[a[i]] = 0
        q[a[i]] = q[a[i]] + 1
    return(q)

def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)
 
def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))
 
def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

def transpose(a):
    n,m = len(a),len(a[0])
    b = [[0] * n for i in range(m)]
    for i in range(m): 
        for j in range(n): 
            b[i][j] = a[j][i]
    return(b)

#-----------------------------------------------------------------------#
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

ans = 0
c = 1
a = 7

if N%2 == 0 :
    ans = -1
else:
    while(ans==0):
        if(a%N==0):
            ans = c
        else:
            a = str(a) + '7'
            a = int(a)
            c += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
k_max = 10 ** 7
k = int(input())

if k % 2 == 0:
    print('-1')
else:
    for i in range(1,k_max+1):
        k_temp = k * i
        if str(k_temp).count('7') == len(str(k_temp)):
            print(len(str(i*k)))
            break

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Aug  2 21:35:25 2020

@author: aruto
"""

def power_func(a,n,p):
        bi = str(format(n,"b"))#2進表現に
        res = 1
        for i in range(len(bi)):
            res = (res*res) %p
            if bi[i] == "1":
                res = (res*a) %p
        return res
    

N = int(input())
if N%7 == 0:
    N = N//7

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

else:
    a = 1
    i = 1
    
    N = 9*N
    
    while a != 0:
        a = power_func(10,i,N)-1
        i += 1
    print(i-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
cnt, amari = 0, 0
a = []
while True:
    cnt += 1
    amari = (amari*10+7)%k
    if amari in a:
        ans = '-1'
        break
    elif amari == 0:
        ans = cnt
        break
    else:
        a.append(amari)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

seven = 7


if K%2==0:
  print("-1")
elif K%5==0:
  print("-1")
else:

  while True:
    if seven%K==0:
      print(len(str(seven)))
      break
    else:
      seven = seven*10+7

Submission status: Time Limit Exceeded

Solution code:
def function(K):
    if K % 2 == 0:
        return -1
    else:
        number = 7
        ans = 1
        while ans > 0:
            if number % K == 0:
                return ans
            number = number*10+7
            ans += 1
        return ans


if __name__ == '__main__':
    K = int(input())
    print(function(K))

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
nana = 7
k = K
i = 1
j = 1
ehehe = 1

if K % 2 == 0:
    print("-1")
else:
    while nana > 0:

        while k <= nana:
            k = K * i
            if nana % k == 0:
                print(j) 
                ehehe = 0
                break
            i += 1
        
        if ehehe == 0:
            break

        nana += 10 ** j * 7
        j += 1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():

    K = int(input())
    if K%2 == 0:
        print(-1)
    else:
        finish = True
        num = 7
        count = 1
        while finish:
            if num>=K:
                if num%K == 0:
                    finish = False
                else:
                    num = num*10 + 7
                    count += 1
            else:
                num = num*10 + 7
                count += 1
        print(count)
resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys

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

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

K = "7"

for i in range(1000000):
    S = int(K)
    if S % N == 0:
        print(i+1)
        sys.exit()
    K = K + "7"

print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

n = "7"
if k%2 != 0:
    for _ in range(k):
        if int(n)%k == 0:
            print(len(n))
            exit()
        else:
            n = n + "7"
    else:
        print("-1")
        exit()
else:
    print("-1")

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

else:
  i = 0
  while i >= 0:
    tmp_n = 0
    for j in range(i):
      tmp_n = tmp_n + 10**j * 7

    # print('tmp_n: ', tmp_n)
    if tmp_n != 0 and tmp_n % K == 0:
      break
    i += 1
    
  print(i)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

L = 7
m = L % K
if K % 2 == 0:
    print(-1)
    exit()
c = 1
while True:
    if (m * (10 ** c - 1) // 9) % K == 0:
        print(c)
        exit()
    c += 1

Submission status: Time Limit Exceeded

Solution code:
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
# stdin = open("sample.txt")


MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (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

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def main():
    K = int(stdin.readline().rstrip())
    if K % 2 == 0 or K % 5 == 0:
        print("-1")
    else:
        for n in range(1,1000000):
            an = (70*(10**(n-1))-7)//9
            if an % K == 0:
                print(n)
                break
        
    
main()

Submission status: Time Limit Exceeded

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

    if K % 2 == 0:
        return -1
    elif K % 5 == 0:
        return -1

    an_min = 7

    while True:
        if an_min % K == 0:
            return len(str(an_min))

        an_min = an_min * 10 + 7

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

Submission status: Time Limit Exceeded

Solution code:
a = "7"
k = int(input())
ans = 1
arr = 10**4
while ans < arr:
    if k%2 == 0:
        ans = arr
        break
    if int(a) < k:
        ans += 1
        a += "7"
        continue
    if int(a)%k == 0:
        break
    ans += 1
    a += "7"

if ans == arr:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
a = int(input())
b = "7"
if a % 2 == 0:
  print("-1")
  sys.exit( )
else:
  while int(b) % a != 0:
    b = b + "7"
print(str(len(b)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
ans = 0
count = 1

if k%2 == 0 or k %5 == 0 :
    print(-1)
else :
    s = 7
    while ans == 0 :
        if s%k == 0 :
            ans = count
        else :
            s += 7*(10**count) % k
            count += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
n=int(input())
num=7
sm=1
if(num%n==0):
    #print("Here")
    print(1)
    exit(0)
for i in range(2,n+1):
    num=num*10+7
    if(num%n==0):
        print(i)
        sm=0
        break
if(sm==1):
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
#k = 2

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

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

Submission status: Time Limit Exceeded

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

i = 0
A = 7 % K
flag = True
while flag:
    if A == 0:
        print(i+1)
        flag = False
    i += 1
    A = (10 * A + 7) % K

Submission status: Time Limit Exceeded

Solution code:
K = input()
X =str('7')*int(len(K))
count = len(X)

while(1):
    if int(K)%2 == 0:
        print(-1)
        break
    elif int(X)%int(K) == 0:
        print(count)
        break
    else:
        X = X + '7'
        count = count + 1

Submission status: Time Limit Exceeded

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

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

print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import sqrt
def main():
    k = int(input())
    if k % 2 == 0:
        print(-1)
        sys.exit()
    ok = k
    while True:
        ks = str(k)
        ksc = [c == '7' for c in ks]
        if all(ksc):
            r = len(ks)
            print(r)
            sys.exit()
        else:
            k += ok

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

if k%2 == 0 or k%5 ==0:
    print(-1)
else:
    a = 7
    while a%k != 0:
        a = int(str(a)+'7')
    print(len(str(a)))

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

seq_str = len(str(k)) * '7'
seq_int = int(seq_str)

cnt = len(str(k))

#print(seq_str, seq_int)

while seq_int % k != 0:
    cnt += 1
    seq_int = seq_int * 10 + 7

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

sev = '7'
cnt = 1

while int(sev) % k != 0:
  if cnt > 10**6:
    cnt = 0
    break
  sev += '7'
  cnt += 1
  
if cnt == 0:
  print(-1)

else:
  print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

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

print(-1)

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()]
    M = 10 ** 9
    if K % 2 == 0:
        print(-1)
        exit()

    for i in range(3, int(K ** 0.5) + 2, 2):
        if K % i == 0:
            break
    else:
        M = K - 1

    N = 7
    for i in range(1, 10 ** 12):
        # print(f"{N = }")
        N %= K
        if not N:
            break
        elif M < i:
            i = M
            break
        N = N * 10 + 7

    print(i)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

n = 1
x = 7


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

while 1:
  if x % K == 0:
    print( n )
    break
  x = (x * 10 + 7) % K
  n += 1
  if x == 7:
    print( -1 )
    break
#

Submission status: Time Limit Exceeded

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


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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
temp = num
ans = 1
while temp > 10:
    temp %= 10
# print(temp)
if temp in [1, 3, 7, 9]:
    sa = 7
    while True:
        if sa % num == 0:
            print(ans)
            break
        else:
            sa *= 10
            sa += 7
            ans += 1
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

count = 0
ans = 1

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

Submission status: Time Limit Exceeded

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

k = int(input())
#b = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

if k >= 10**4:

    s = set()
    keta = 10**6
    prev = int('1'*keta)*7
    ans = keta

    while True:
        mod = prev%k
        if mod in s:
            print(-1)
            break
        if not mod:
            print(ans)
            break
        else:
            s.add(mod)
            prev //= 10
        ans -= 1

else:

    s = set()
    prev = 0
    ans = 1

    while True:
        curr = prev*10+7
        mod = curr%k
        if mod in s:
            print(-1)
            break
        if not mod:
            print(ans)
            break
        else:
            s.add(mod)
            prev = curr
        ans += 1

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

X = []
s = len(str(K))
for i in range(s):
    X.append(7)

while True:
    Y = int("".join(map(str,X)))
    if Y % K == 0:
        print(len(X))
        break
    elif K % 2 == 0:
        print(-1)
        break
    else:
        X.append(7)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())

seven = 7


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


  while True:
    if seven%K==0:
      print(len(str(seven)))
      break
    else:
      seven = seven*10+7

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
if K%2==0 or K%5==0:
	print("-1")
	exit()
for n in range(1,10**6+1):
	if (7*(10**n-1)//9)%K==0:
		print(n)
		exit()
print("-1")

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
i=7
j=10
n=1
if K%2==0:
  print("-1")
else:
  while not i%K==0:
    i=i+7*j
    j=j*10
    n=n+1
  print(n)

Submission status: Time Limit Exceeded

Solution code:

def next7(s):
    return s * 10 + 7


def submit():
    k = int(input())

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

    s = 7
    ans = 1
    while s % k:
        s = next7(s)
        ans += 1

    print(ans)


submit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

import numpy as np
# 行数
K = int(input())
flg=False
if K%2==0:
  print(-1)


else:
  num = 7;
  for i in range(100000):
    # print(num)
    if num%K==0:
      flg=True
      print(i+1)
      break
    else:
      num=num*10+7

  if is_prime(K) and flg==False:
    print(K-1)
  elif(flg==False):
    print(-1)




# # S =[1]*N
# stock = 0 #株の数
# money = 1000 #所持金
# for i in range(N):
#   if i>0:
#     if A[i-1]<A[i]: #売る
#       money += stock*A[i]
#       stock = 0
#   if i!=N-1:
#     if A[i]<A[i+1]: #買う
#       stock += int(money/A[i])
#       money -= stock*A[i]
# print(money)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = "7"
k = int(input())
ans = 1
while ans < 10**5:
    if k%2 == 0:
        ans = 10**6
        break
    if int(a) < k:
        ans += 1
        a += "7"
        continue
    if int(a)%k == 0:
        break
    ans += 1
    a += "7"

if ans == 10**6:
    print(-1)
else:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
score = int(input())
keta = 0
answer = 0
alpha = 7
if score % 2 == 0 or score % 10 == 5:
    print(-1)
elif score == 999983:
    print(999982)
else:
    while answer == 0:
        if alpha % score != 0:
            alpha = alpha*10 + 7
        else:
            answer = 1
        keta += 1
    print(keta)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
i=1
li=[]
while True:
    nana='7'*i
    N=int(nana)
    #print(N%k)
    if N%k==0:
        print(i)
        break
    if len(li)!=len(set(li)):
        print(-1)
        break
    i+=1

Submission status: Time Limit Exceeded

Solution code:
import sys
x = int(input())
if x%2 == 0:
    print(-1)
    sys.exit()
y = 7
i = 1
while y%x != 0:
    i = i + 1
    y = y*10 + 7
print(i)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = 1
c = 0
d = 0
if a%2==0:
  print("-1")
else:
  while b > 0:
    c = 10*c+7
    d = d+1
    if c%a==0:
      b = -1
  print(d)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
print(i)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

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

print(k-1)
exit()