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
c = 1
l = [7]
if k%10 == 2 or k%10 == 4 :
    print(-1)
elif k%10 == 5 or k%10 == 6 :
    print(-1)
elif k%10 == 8 :
    print(-1)
else :
    for i in l :
      if n % k == 0 :
        print(int(len(l)))
        break
      else :
          c += 1
          l.append(int(str(n)+"7"))

Submission status: Time Limit Exceeded

Solution code:
# Coding is about expressing your feeling and there is always a better way to express your feeling _feelme
import sys,math
#sys.stdin,sys.stdout=open('input.txt','r'),open('output.txt','w')
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# np.set_printoptions(sign=' ',legacy='1.13') # legacy add space at sign position
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(arr, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if arr[mid] == val:return mid
        elif arr[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,arr):
    for i in range(1,n):arr[i]+=arr[i-1]
    return arr;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;


def fun(k):
    current=7
    for i in range(1,10**6):
        if current%k==0:
            return i
        current*=10
        current+=7
    return -1
k = ii1()
print(fun(k))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
S = '7'
ans = 0
while ans == 0:
    if int(S)%K == 0:
        ans = 1
    elif K%2 == 0 or K%5 == 0:
        break
    else:
        S += '7'

if ans == 1:
    print(len(S))
else:
    print('-1')

Submission status: Time Limit Exceeded

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

if k % 2 == 0:
  print(-1)
  quit()
  
while t % k != 0:
    kou += 1
    t = 10 * t + 7
    
print(kou)

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
c = 1
n = 7
f=0
while(n%t !=0):
    c +=1
    n = n*10 + 7
    if(len(str(n))>10000):
        print(-1)
        f=1
        break
if(f!=1):
    print(c)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

sept = 7

count = 1
for i in range(1000000):
    if sept % k == 0:
        print(count)
        exit()

    else:
        sept = int(str(sept) + '7')
        count += 1

else:
    print('-1')

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys


k = int(input())

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

for i in range(1, 1000001):
    s = '7' * i
    number7 = int(s)

    if number7 % k == 0:
        print(i)
        sys.exit()
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import sys

K = input()
tmp = len(K)
K = int(K)

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

flag = 0
num = 7
count = tmp - 1

for i in range(count):
    num = num * 10 + 7

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

num = ""
while True:
    num += "7"
    kazu = int(num)
    if kazu % K == 0:
        print(len(num))
        break

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

str_l = '7'
int_l = 7
ans = 1

while int_l % n != 0:
  if n % 2 == 0:
    ans = -1
    break
  str_l += '7'
  int_l = int(str_l)
  ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
a=0
while True:
  a+=1
  if str(k*a).count("7") == len(str(k*a)):
    break
print(len(str(k*a)))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
	K = int(input())
	A = '-1'
	if K%2==0:
		None
	elif K%5==0:
		None
	else:
		for i in range(1,1000000):
			if int('7' * i)%K==0:
				A = i
				break
	print(A)
resolve()

Submission status: Time Limit Exceeded

Solution code:
import math

k = int(input())
if k % 2==0:
    print(-1)
else:
    keta = math.floor((math.log(k ,10))) + 1
    n = keta
    p = 0
    for i in range(keta):
        p += 7*(10**(i))
    while(True):
        if p % k ==  0:
            print(n)
            break
        else:
            n += 1
            p  += 7  *  10**(n-1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys 

readline = sys.stdin.readline

K = int(input())

seven_string = '7'
judge = False
for i in range(K + 1):
    seven_int = int(seven_string)
    if seven_int % K == 0:
        print(i+1)
        judge = True
        break

    seven_string += '7'

if not judge:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
k = int(input())
kx = k
if k % 2 == 1:
    while True:
        num = list(str(kx))
        if all(kx == "7" for kx in num):
            print(len(str(kx)))
            break
        kx = kx + k
else:
    print("-1")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

L = '7'
c = 1
while True:
    k = int(L*c)
    if k % K == 0:
        print(c)
        exit()
    c += 1

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

seen = set()
base = 0
n = 0
while 1:
    n += 7 * 10**base   
    m = n % K
    if m == 0:
        print(base+1)
        break
    if m in seen:
        print(-1)
        break
    seen.add(m)
    base += 1

Submission status: Time Limit Exceeded

Solution code:
sevens = "7"
K = int(input())
idx = 1
while True:
  if int(sevens) % K == 0:
    print(idx)
    break
  else:
    sevens = sevens + "7"
    idx = idx + 1

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

k = int(input())
r = np.zeros(k)

out = 1
s = 7 % k
while s != 0:
    n = s + 7 * (10 ** out)
    s = n % k
    if r[s] == 1:
        out = -1
        break
    if s != 0:
        r[s] = 1
    out += 1
print(out)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
count = 1
a='7'
if K%2==0:
  print('-1')
else:
  while int(a)%K!=0:
    count += 1
    a = a + '7'
  print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    k = int(input())
    tmp = 7
    cnt = 0
    if k%2 == 0:
        print(-1)
        return

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



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
T = 1
S = 7
X = 1000000
for i in range(X):
    Q = S//K
    if Q * K == S:
        print(T)
        break
    else:
        T += 1
        S = S*10 + 7
if T == 1000001:
    print(-1)

Submission status: Time Limit Exceeded

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

while (True):
    if(a_7 % K == 0):
        print(count)
        break
    elif(a_7 >= 1000000):
        print('-1')
    else:
        a_7 += 10**count*7
        count += 1

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

if K % 2 == 0:
  print(-1)
  exit(0)
  
nana = 7
count = 1
flag = 0
while flag == 0:
  if nana % K == 0:
    print(count)
    flag = 1
  nana = nana + 7 * (10 ** count)
  count += 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
total7 = 0

if k%2 == 0 or k%5 == 0:
    print(-1)
else:
    c7 = len(str(k))
    for i in range(c7):
        if i > 0:
            total7 += 7 * (10**i)
        else:
            total7 += 7

    while(1):
        if total7 % k == 0:
            break
        
        total7 += 7 * (10**c7)
        c7 += 1
        
    print(c7)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
flag=1
ans=1
r=7%k
p=r
while flag!=0:
    if r%k==0:
        flag=0
    else:
        ans+=1
        p=(p*10)%k
        r+=p
print(ans)

Submission status: Time Limit Exceeded

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

print(-1)
exit()

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
        if base_number % k == 0:
            print(count)
            break

Submission status: Time Limit Exceeded

Solution code:
a = "7"
k = int(input())
ans = 1
while ans < 10**6:
    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:
def is_multiple(s, base, m):
    temp = 0
    for i in range(len(s)):
        temp = temp*base + int(s) % m
    if temp == 0:
        return True
    return False

k = int(input())
count = 0

while True:
    count += 1
    temp = '7' * count
    if is_multiple(temp, 10, k):
        break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math

K = int(input())
cnt = 1
S = 7

while True:
    if S % K == 0:
        break
    S = S + 10 ** cnt * 7
    if cnt >= K:
        cnt = -1
        break
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
K = int(input())
num = 0
for i in range(10**6):
    num +=7*10**(i)
    if num % K ==0:
        print(i+1)
        exit()

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

j=0
ans=0
a=0
while True:
    a=a*10+7
    ans+=1
    if a%K==0:
        break
    
    if ans>K:
        ans=-1
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
i = 0
Num = 7

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
ans = -1
if k % 2 == 1:
  f = 0
  m = 1
  seven = ['7']
  p = list(set(list(str(k * m))))
  while f == 0:
    if seven == p:
      ans = len(str(k * m))
      break
    else:
      m += 1
      p = list(set(list(str(k * m))))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

n = "7"*len(str(K))
for i in range(len(str(K)), len(str(K))*10000):
    if int(n) % K == 0:
        print(i)
        break
    n += "7"
else:
    print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

count = 0
times=1
n = 0

while True:
    n += 7*times
    if n % K ==0:
        count +=1
        break
    times *=10
    count +=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

l = [0] * k
count = 0
for n in range(k):
    l[n] = l[n-1] + 7 * 10 ** count
    count += 1


for i in range(k):
    if l[i] % k == 0:
        print(i+1)
        break
    elif i == k-1:
        print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

def find_7s(n):
  if n%2==0:
    return -1
  sevens=0
  for d in range(100000):
    sevens += 7*10**d
    if sevens%n==0:
      return d+1
  return -1

print(find_7s(K))

Submission status: Time Limit Exceeded

Solution code:
import sys


def resolve(in_):
    k = int(next(in_))
    if not k % 2:
        return -1

    seven = 7 % k

    for i in range(1, 100000000):
        if not seven:
            return i
        i += 1
        seven = seven * 10 + 7
        if seven >= k:
            seven %= k

    return -1

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

if k%2 == 0:
  count = '-1'
else:
  count = 1
  num = 7
  while True:
    if num%k != 0:
      count += 1
      num = num*10 + 7
      continue
    else:
      # count += 1
      break

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res
 
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(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 main():  #startline-------------------------------------------
    k = int(input())
    a = 0
    ans = 0
    if k % 2 == 0:
        print(-1)
        exit()
    for i in range(1,10**6+1):
        a = a * 10 + 7
        if a % k == 0:
            ans = i
            break
    print(ans)
        
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

n = 7
if k%2 != 0:
    while not(n%k == 0):
        n = int(str(n) + "7")
        if len(str(n)) == 10**6:
            print("-1")
            exit()
    else:
        print(len(str(n)))
else:
    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()]

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

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

    print(i)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import datetime
import string
import re
import math

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())

if k%2==0:
    print(-1)
else:
    for i in range(1,10**7):
        x="7"*i
        if int(x)%k==0:
            print(i)
            exit()

Submission status: Time Limit Exceeded

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

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

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

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

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

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

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

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

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

    return count

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

    print(main(_K))

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

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


now=0
count=0
N=0
flag=False
while True:
    now+=(7*pow(10,count, K))%K
    now%=K
    #print(N)
    if not flag:
        N+=7*10**(count)
    if N>=K:
        flag=True
    #print(now, count)
    if now==0 and flag:
        print(count+1)
        exit()
    count+=1
    if count>=10**7:
        break


print(-1)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

    elif int(seven) % k == 0:
        count += 1
        break
    else:
        count += 1
        seven += '7'

print(count)

Submission status: Time Limit Exceeded

Solution code:
##C
k = int(input())
number = str(7)
cnt = 1
if k % 2 == 0:
    print(-1)
    exit()
while 1:
    if int(number) % k == 0:
        print(cnt)
        break
    else:
        cnt += 1
        number += str(7)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
ans=1
u=[]
o = 7
if k%2 == 0:
    print(-1)
    exit()
while not(o in u):
    o = o % k
    if o == 0:
        print(ans)
        exit()
    else:
        u.append(o)
        o = o*10 + 7
        ans+=1
print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

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


now=0
count=0
N=0
flag=False
while True:
    now+=(7*pow(10,count, K))%K
    now%=K
    #print(N)
    if not flag:
        N+=7*10**(count)
    if N>=K:
        flag=True
    #print(now, count)
    if now==0 and flag:
        print(count+1)
        exit()
    count+=1


print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys


def resolve(in_):
    k = int(next(in_))
    if not k % 2:
        return -1

    seven = 7 % k

    for i in range(1, 1000000000):
        if not seven:
            return i
        i += 1
        seven = seven * 10 + 7
        seven %= k

    return -1

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
c = 1
b = False

while b == False:
  n = 0
  for i in range(c):
    n += 7 * (10 ** i)
  if n % K == 0:
    b = True
    print(c)
  c += 1
  if c > 2000:
    print(-1)
    b = True

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

check = False
if k%2 == 0:
  check = True
  
if check == False:
  check_s = "7"
  while(True):
    if int(check_s)%k == 0:
      break
    check_s += "7"
  print(len(check_s))
else :
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
#C

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

for i in range(1,10**7):
    tmp= 7*(pow(10,i)-1) // 9
    if tmp%K==0:
        ans=i
        break
print(i)

Submission status: Time Limit Exceeded

Solution code:
def main():

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

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
n = 0
frag = 0
sevens = ""
while frag==0:
    sevens = sevens + "7"
    n+=1
    if int(sevens)%k==0:
        frag=1
print(n)

Submission status: Time Limit Exceeded

Solution code:
def seven(n):
    ans=0
    for i in range(n):
        ans*=10
        ans+=7
    return ans
k=int(input())
if(k%2==0):
    print(-1)
else:
    x=1
    while(1):
        if(seven(x)%k==0):
            print(x)
            break
        else:
            x+=1

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=""
if(n%2==0):
  print("-1")
else:
  d=""
  d=str(n)
  l=len(d)
  
  for i in range(0,l):
    s=s+"7"
  #print(s)
  while(1):
    if(int(s)%n==0):
      print(len(s))
      break;
    else:
        s=s+"7"

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
N = 0
a = 0
f = 0

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

while(f == 0):
    a += 1
    N = N * 10 + 7
    if(N % K == 0):
        print(a)
        f += 1

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))


K = int(input())
def main():
    k = 7
    count = 1
    if K %2==0:
        print(-1)
        return
    while True:
        if k % K == 0:
            print(count)
            return
        k = (k+7*(10**count))%K
        count += 1


main()

Submission status: Time Limit Exceeded

Solution code:
lst=['7'*k for k in range(1, 11111)]
k=int(input())
i=0
ok=False
for _ in lst:
    p=int(lst[i])
    if p%k==0:
        ok=True
        print(i+1)
        break
    i+=1
    
if ok==False:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

a = 7
p = -1
ans = 0

while True:
    t = a % K
    ans += 1
    if t == 0:
        print(ans)
        break
    if t == p:
        print(-1)
        break
    a = 10*t + 7
    p = t

Submission status: Time Limit Exceeded

Solution code:
K = int(input(""))

num = 7

if K%2==0:
    print(-1)
else:  
    while not num%K==0:
        num = num*10 + 7
  
    print(len(list(str(num))))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
if K % 2 == 0:
  print(-1)
  exit()
i = 1
while True:
  N = int("7" * i)
  if N % K == 0:
    break
  i += 1
print(i)

Submission status: Time Limit Exceeded

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