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())
if k%2==0 or k%5==0:
    print(-1)
    exit()
    
def so(n):
  for i in range(2,int(n**0.5)+1):
    if n%i==0:
      return False
  else:
    return True
    
t = 55000
if k%7==0:
  k//= 7
l = len(str(k))
s = int(str(1)*l)
ind = l
while t!=0 :
    if s%k==0:
        print(ind)
        exit()
    else:
        s = s*10+1
        ind += 1
    t -=1
    
if so(k)==True:
  print(k-1)
  exit()
else:
  print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

K = INT()

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

cnt = 1
tmp = 1
while K*tmp != int("7"*cnt):
	if K*tmp > int("7"*cnt):
		cnt += 1
	if K*tmp == int("7"*cnt):
		break
	tmp += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())


def make_divisors(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table


a = 1
n = 7
l = 10 ** 16
p = X % 2

while True:
    if p == 0:
        print(-1)
        break;
    m = make_divisors(n)
    if a == 1:
        if X in m:
            print(a)
            break;
    if a >= 2:
        r = list(set(m)-set(z))
        if X in r:
            print(a)
            break;
    if n > l:
        print(-1)
        break;
    else:
        a += 1
        n = n * 10 + 7
        z = m

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
if K%2==0:
    print('-1')
    exit()
A='7'*(10**6)
a=int(A)
i=10**6
l=[]
while True:
    a//=10
    if a%K==0:
        break
    elif a in l:
        print('-1')
        break
    l.append(a)
    i-=1
arr=[]
x=i
for j in range(2,int(i**0.5)+1):
    if x%j==0:
        arr.append(i)
        while x%j==0:
            x//=j
if x!=1:
    arr.append(x)
for k in arr:
    if int('7'*k)%K!=0:
        arr.remove(k)
if arr==[]:
    print(i)
else:
    print(min(arr))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    K = int(input())
    # = "7"*999982
    #print(int(t)%999983)

    if K%2 == 0 or K%5 == 0:
        print(-1)
    else:
        f = len(factorization(K))
        i = 0
        while(20000>i):
            i+=1
            if 7 * (10**i-1)//9 %K == 0:
                print(i)
                return
        if f > 2:
            print(-1)
        else:
            print(K-1)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
for i in range(1,10**6):
    n = (7*10**i -7)//9
    if n%x == 0:
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


k=int(input())
#print(prime_factorize(k))
l=factorization(k)
#print(l)
mnum=0
for i in range(len(l)):
    mnum=max(mnum,l[i][0]**l[i][1])
#print(mnum)
if k%2==0:
    print(-1)
    exit()
for i in range(k):
#for i in range(mnum):
    n=int("7"*(i+1))
#    print(n)
    if n%k==0:
        print(i+1)
        exit()
print(-1)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
K = int(input())

def factorize(target_number):
    factor_list = []
    while target_number % 2 == 0:
        factor_list.append(2)
        target_number //= 2
    factor = 3
    while factor * factor <= target_number:
        while target_number % factor == 0:
            target_number //= factor
            factor_list.append(factor)
        factor += 2
    if target_number > 1:
        factor_list.append(target_number)
    return factor_list

fact_list = factorize(K)
if fact_list.count(2) > 0 or fact_list.count(5) > 0:
    print(-1)
else:
    num = 7
    for i in range(10 ** 6):
        if num % K == 0:
            print(i + 1)
            break
        num = num * 10 + 7

Submission status: Time Limit Exceeded

Solution code:

k=int(input())
ans=-1
s=''
for i in range(k):
    s+='7'
    s=int(s)
     
    if s%k==0:
        ans=i+1
        break
    s=str(s)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = True
b = 0 
count = 0
ans = 0

if (n % 2) == 0:
  a = False
  ans = -1
while  a:
  b += 7 * 10**count
  div = b % n 
  if div == 0:
    ans = count + 1
    break
  count += 1

print (ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

m = 7%k
ans = 1
jud = True
p = 70%k
while m != 0:
    m = (m + p)%k
    ans += 1
    p = p*10%k
    if p == 0:
        jud = False
        break
if jud:
    print(ans)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
import time
k = int(input())
tick = time.time()

if k == 7:
    ans = 1
elif k % 2 == 0:
    ans = -1
else:
    i = 0
    while True:
        i += 1
        if time.time() - tick > 1.995:
            ans = -1
            break
        tgt = int("7" * i)
        if tgt % k == 0:
            ans = i
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
input = stdin.readline
k= int(input())
if k % 2 == 0:
  print(-1)
i = 1
fav_num = 7
while True:
  if fav_num % k != 0:
    pass
  a = fav_num % k
  i +=  1
  b = 7*(10**i)%k
  fav_num = (a+b)

Submission status: Time Limit Exceeded

Solution code:
import math

K = int(input())
if K % 2 == 0:
    print(-1)
else:
    a = 9 * K + 7
    def ok(n):
        return 63 * 10 ** n >= a
    left = 1
    right = 10 ** 9
    while right - left > 1:
        mid = (right + left) // 2
        if ok(mid):
            right = mid
        else:
            left = mid
    print(right - 1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

pn=factorization(k)

go =0
keta = len(str(k))
sevens = []

if k % 2 == 0 or k %5 == 0:
    print(-1)
elif str(k)[-1] == "3":
    for i in range(9,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "7":
    for i in range(1,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "9":
    for i in range(3,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "1":
    for i in range(7,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))

Submission status: Time Limit Exceeded

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

base_number = 0
if k % 2 == 0:
    print("-1")
if k % 2 == 1:
    for i in range(100000000):
        base_number = 7 * (((10**(i+1))-1)//9)
        q, mod = divmod(base_number, k)
        if mod == 0:
            print(i+1)
            break

Submission status: Time Limit Exceeded

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

global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    K = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[0].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    if K % 2 == 0:
        return [-1]
    if K % 5 == 0:
        return [-1]

    amari = 10**6 - (10**6 // K) * K

    for k in range(1, K+1):
        mini_k = -(-k // 6)
        target = 0
        for m in range(mini_k):
            amari_m = 1
            for _ in range(m):
                amari_m *= amari
                q, amari_m = divmod(amari_m, K)
            q, amari_m = divmod(amari_m, K)
            if m == mini_k-1:
                target += int('7' * (k-6*m)) * amari_m
            else:
                target += 777777 * amari_m
        log(f'target=[{target}]')
        q, mod = divmod(target, K)
        if mod == 0:
            return [k]

    return [-2]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['101']
        lines_export = [4]
    if pattern == 2:
        lines_input = ['2']
        lines_export = [-1]
    if pattern == 3:
        lines_input = ['999983']
        lines_export = [999982]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


mod=1000000007
def combinations_count_mod(n, r):
    r = min(r, n - r)
    numer = reduce(lambda x,y: x*y%mod, range(n, n - r, -1), 1)
    denom = pow( reduce(lambda x,y: x*y%mod, range(1, r + 1), 1) , mod-2, mod)
    return numer * denom % mod



def main():
    k = int(input().strip())
    if k%2==0:
        print(-1)
    else:
        temp=0
        for i in range(10**10):
            temp+=(7*(10**i)) % k
            temp=temp%k
            if temp==0:
                print(i+1)
                return



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
ans = -1
if K in [2,5]:
    pass
else:
    num = 7
    ans = 0
    while True:
        ans += 1
        if num % K == 0:
            break
        else:
            num = num * 10 + 7
print(ans)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())


def make_divisors(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table


a = 1
n = 7
l = 10 ** 18
p = X % 2

while True:
    if p == 0:
        print(-1)
        break;
    m = make_divisors(n)
    if a == 1:
        if X in m:
            print(a)
            break;
    if a >= 2:
        r = list(set(m)-set(z))
        if X in r:
            print(a)
            break;
    if n > l:
        print(-1)
        break;
    else:
        a += 1
        n = n * 10 + 7
        z = m

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

    K=int(input())

    str=""
    for i in range(1000000):
        str+="7"
        if int(str)%K==0:
            print(i+1)
            break

    # print(factorization(777777))

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

lis = []
val = -1
num = 0
tens = 1
for i in range(1, 10 ** 6 + 1):
  num += 7 * tens
  if num % K == 0:
    print(i)
    exit()
  tens *= 10

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
K = int(S)

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

i = 1
A = 7
while i <= 10**6 + 1:
    if A % K == 0:
        print(i)
        exit()
    A = A*10 + 7
    i += 1
print(-1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

k=int(input())

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

num=7
cnt=1
while num%k!=0:
  num=str(num)
  num+='7'
  num=int(num)
  cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
k=int(input())
i=len(str(k))
cou=i
a=True
if k%2==0:
    print('-1')
    sys.exit
while a==True:
  b=['1']*i
  c=int(''.join(b))
  if 7*c%k==0:
    print(cou)
    a=False
  
  cou+=1
  i+=1

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

for i in range(100000000):
  	
	cal = str(K * (i+1))
	length = len(cal)

	num = 0
    
	for j in range(int(length)):
		if cal[j] == "7":
			num = num +1
            
	if length == num:
		print(length)
		break

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    k = i_input()

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

    if k == 999983:
        print(999982)
        exit()

    tmp = 7
    count = 1        

    while count < 10 ** 6:
        if int(tmp) % k == 0:
            print(count)
            exit()
        count += 1
        tmp = tmp * 10  + 7

    print(-1)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# 1≤K≤10**6
# Kは整数である。
#7x{(10ⁿ-1)/9}

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

base_number = 0
if k % 2 == 0:
    print("-1")
if k % 2 == 1:
    for i in range(100000000):
        base_number = 7 * ((pow(10,(i+1))-1)//9)
#         print(base_number)
        q, mod = divmod(base_number, k)
        if mod == 0:
            print(i+1)
            break

Submission status: Time Limit Exceeded

Solution code:
#N, K = map(int,input().split())
#A = list(map(int,input().split()))
K = int(input())
if K % 7 == 0:
    K //= 7
if K % 2 == 0:
    print(-1)
    exit(0)
n = 1
r = 1 % K
while r != 0:
    r = (10*r+1) % K
    n += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    K = int(input())
    if K%2==0 or K%5==0 :
        print(-1); return
    for i in range(1, K+1):
        if int("7"*i)%K == 0:
            print(i); return
    print(-1)
resolve()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
count = 1
for i in range(1,10**6+2):
    a = str(7)*i
    if int(a)%k == 0:
        print(count)
        break
    elif k%2 == 0:
        print('-1')
        break
    elif k == 999983:
        print(999982)
        break
    count += 1

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

x = 7
for i in range(K):
    # print(f'x: {x}, K: {K}')
    if x % K == 0:
        print(i + 1)
        break
    x = int(str(x) + '7')
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
seven = 7
plus = 70
if K%2 ==0:
    print(-1)
    exit(0)
a = "7"
for i in range(1000000):
    if int(a)%K == 0:
        print(len(a))
        exit(0)
    a += "7"

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
k_str = str(k)

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    seven = 7
    seven_str = "7"
    while int(seven_str) % k != 0:
        seven_str += "7"
    print(len(seven_str))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

import sys
K=int(input())

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

retsu = ["7"]
nana=[7]
for i in range(1,10**6):
    retsu.append("7")
    num=int(''.join(retsu))
    nana.append(num)
for j in range(len(retsu)):
    if retsu[j]%K==0:
        print(j+1)
        sys.exit()
print(-1)

Submission status: Time Limit Exceeded

Solution code:
K=int(input())

MAX=10**6

for i in range(1,MAX+1):
  if i%4==0:continue
  if i%25==0:continue
  if i%36==0:continue
  X=7*int("1"*i)
  if X%K==0:
    print(i)
    exit(0)
print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict
K = int(input())

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

for i in range(10**6):
    cnt += 1
    now = now*10 + 7
    if now % K == 0:
        print(cnt)
        sys.exit(0)

print(-1)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
K = int(input())
num = 0
if K % 5==0 or K % 2==0:
    print(-1)
    exit()
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:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
k = I()
if k%2 == 0:
    print(-1)
    exit()
a = ""
for i in range(20000):
    a += "7"
    if int(a)%k == 0:
        print(i+1)
        exit()
print(k-1)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
if k%2==0:
    print(-1)
    exit()
for i in range(1,10**6):
    # v=int('7'*l)
    v=(10**i-1)*7//9
    if v%k==0:
        break
print(i)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
def modpow(a, n, p):
    '''aをn乗した値のmod(p)を求める
    '''
    if n == 0:
        return 0
    if n == 1:
        return a % p
    if n % 2 == 1:
        return (a * modpow(a, n - 1, p)) % p
    else:
        t = modpow(a, n // 2, p)
        return (t * t) % p

K = int(input())
ans = 0
if K % 2 == 0:
    ans = -1
else:
    seven = 7
    for i in range(1000000):
        seven = seven + 7 * modpow(10, i, K)
        seven %= K
        if seven == 0:
            ans = i+1
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
sbox=[]
for i in range(1,k+1):
    x=0
    num=i
    for j in range(i):
        x=x*10+7
    surplus=x%k
    if surplus==0:
        print(num)
        break
    else:
        if surplus in sbox:
            print(-1)
            break
        else:
            sbox.append(surplus)
    if k==num:
        print(-1)
        break

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
input = stdin.readline
k= int(input())
if k % 2 == 0:
  print(-1)
i = 1
fav_num = 7
while True:
  if fav_num % k != 0:
    pass
  a = fav_num % k
  fav_num = a + 7*(10**i)
  i +=  1

Submission status: Time Limit Exceeded

Solution code:
#N, K = map(int,input().split())
#A = list(map(int,input().split()))
K = int(input())
if K % 7 == 0:
    K //= 7
if K % 2 == 0:
    print(-1)
n = 1
r = 1 % K
while r != 0:
    r = (10*r+1) % K
    n += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())  # ぜんぜんちがう
ans = -1
 
def moduloseven(K):
	for i in range(500000):
		sev = int(str(7)*(i+1))
		if sev % K == 0:
			ans = i+1
			break
		else:
			ans = K-1
	return(ans)
 
if K % 2 != 0:
	if K % 5 != 0:
		ans = moduloseven(K)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

for k in range(1):
    for i in range(1, 10**9):
        numk = K*i
        keta = len(str(numk))
        sept = int("7" * keta)
        if numk == sept:
            print(keta)
            break
        if keta == 10**2 or i == 10**9-1:
            print(-1)
            break

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

count = 0
ans = 1

while True:
  num = int("7" + "7" * count)

  if k % 2 == 0 or k % 5 == 0:
    print(-1)
    break
  elif num % k == 0:
    print(ans)
    break

  count += 1
  ans += 1

Submission status: Time Limit Exceeded

Solution code:

import collections


def main():
    k = int(input())
    kList = [0] * 10 ** 6
    cnt = 0
    if k % 2 == 0:
        print(-1)
        return
    for i in range(10000000):
        cnt += 1
        kList[i] = ((kList[max(0, i - 1)] + 7 * 10 ** (cnt - 1)) % k)
        if kList[i] == 0:
            break
    print(cnt)


def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy > 0:
        out = str(X_dumy % n)+out
        X_dumy = int(X_dumy/n)
    return out


def is_prime(q):
    q = abs(q)
    if q == 2:
        return True
    if q < 2 or q & 1 == 0:
        return False
    return pow(2, q-1, q) == 1


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

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

print(-1)

Submission status: Time Limit Exceeded

Solution code:
from operator import mod
d = 0
e = -1
i = 1
a = int(input())
while True:
    d = 7 + 10*d
    if mod(a, 2) == 0:
        print(e)
        break
    elif mod(d, a) == 0:
        print(i)
        break
    i += 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
        #print(amari,amari_sum)
        if amari_sum % K == 0:
            return i
        #else:
            #amari_sum %= K

print(main())

Submission status: Time Limit Exceeded

Solution code:
#N, K = map(int,input().split())
#A = list(map(int,input().split()))
K = int(input())

if K % 2 == 0:
    print(-1)
    exit(0)
n = 1
r = 7 % K
while r != 0:
    r = (10*r+7) % K
    n += 1
print(n)

Submission status: Time Limit Exceeded

Solution code:
a = 7
b = 1
N = int(input())
if N%2==0:
  print(-1)
  exit()
if N ==999983:
  print(999982)
  exit()
c = 7
K =True
while K:
  if a%N==0:
    K=False
  else:
    a+=10**b*c
    b+=1
print(len(str(a)))

Submission status: Time Limit Exceeded

Solution code:
X = int(input())


def make_divisors(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n // i)
        i += 1
    table = list(set(table))
    return table


a = 1
n = 7
l = 10 ** 18
p = X % 2

while True:
    if p == 0:
        print(-1)
        break;
    m = make_divisors(n)
    if a == 1:
        if X in m:
            print(a)
            break;
    if a == 2:
        r = list(set(m)-set(z))
        if X in r:
            print(a)
            break;
    if n > l:
        print(-1)
        break;
    else:
        a += 1
        n = n * 10 + 7
        z = m

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
keta = len(str(k))
now = '7' * keta
ans = -1
while len(now) <= 999982:
    if int(now) % k == 0:
        ans = len(now)
        break
    now += '7'
print(ans)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

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


print(ans)

Submission status: Time Limit Exceeded

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

if K%2 == 0:
    print(-1)
elif K%5 == 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:
#C_Repsept
import math
K = int(input())
X = 0
kekka = -1
total = -1
for i in range(K): 
    X = X + pow(10,i) * 7
    kekka = X % K
    if kekka == 0:
        total = i+1
        break
# 出力
print(total)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

num = 0

for i in range(1000000):
    num += 7*10**i
    if num % k == 0:
        print(len(str(num)))
        break

else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())  # ぜんぜんちがう
ans = -1
 
def moduloseven(K):
	for i in range(1000000):
		sev = int(str(7)*(i+1))
		if sev % K == 0:
			ans = i+1
			break
		else:
			ans = K-1
	return(ans)
 
if K % 2 != 0:
	if K % 5 != 0:
		ans = moduloseven(K)
print(ans)

Submission status: Time Limit Exceeded

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

num = 0

if k == 999983:
    print(999982)
    sys.exit()

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
ans = -1
a = 0
for i in range(10000000):
    a = str(a) + '7'
    a = int(a)
    if a % K == 0:
        ans = i +1
        break
print(ans)