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: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

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

def main():
    K = int(input())
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        exit()

    if K == 1:
        print(1)
        exit()
    tmp = 7
    i = 0
    while i < K-1:
        # print(7*tmp)
        if tmp % K == 0:
            print(i+1)
            exit()
        else:
            tmp += 7 * pow(10,(i+1),K) % K
            tmp %= K
            i += 1 
    print(i)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())
if k % 2 == 0 or k == 1:
    print(-1)
    exit()
for i in range(1,1000000):
    target = "7"*(i)
    target = int(target)
    if target % k == 0:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
x = len(str(n))
if n % 2==0 or n % 5 ==0:
    print(-1)
    sys.exit()
p = [i for i in str(n)]
p = list(set(p))
p.sort()
if p[0]=="0" and p[1]=="1":
    print(x+1)
else:
    print(n-1)

Submission status: Wrong Answer

Solution code:
K=int(input())
N=7
c=0
if K%2==0:
    print("-1")
else:
    while N % K != 7 % K:
        c += 1
        N = 7 * (10 ** c)
print(c)

Submission status: Wrong Answer

Solution code:

k = int(input())

ans = 1
t = '7'

exist = False

if k == 1 :
    exist = True

if k % 3 == 0 or k % 7 == 0 or k % 11 == 0 or k % 13 == 0 or k % 37 == 0 or k % 41 == 0 or k % 101 == 0 or k % 239 == 0 or k % 4649 == 0 or k % 41 == 0 or k % 271 == 0 or k % 137 == 0 or k % 73 == 0 or k % 53 == 0 or k % 79 == 0 or k % 17 == 0 or k % 9901 == 0 or k % 9091 == 0 or k % 21649 == 0 or k % 513239 == 0 or k % 909091 == 0 or k % 2906161 == 0 or k % 52579 == 0 or k % 333667 == 0 or k % 999983 == 0 or k % 9901 == 0 or k % 9091 == 0:


    while int(t) <= 10**10000:
        
        # print(t)

        if int(t) % k == 0 :
            exist = True
            break

        t = t + '7'
        ans += 1

if exist == True :
    print(ans)
else :
    print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
k *= 7
l = k % 10
if l == 1:
    m = 7
elif l == 3:
    m = 9
elif l == 7:
    m = 1
elif l == 9:
    m = 3
else:
    m = -1
if m == -1:
    print(-1)
else:
    x = k
    for i in range(10 ** 10):
        s = str(x)
        if len(s) == s.count("7"):
            print(len(s))
            break
        else:
            x = k * m
            m += 10

Submission status: Wrong Answer

Solution code:
# ダメ元コード
k = int(input())

x = 7
if k == 7:
    print(1)
elif k == 999983:
    print(999982)
elif k % 2 != 0:
    for i in range(2, 999983):
        x = x * 10 + 7
        if x % k == 0:
            print(i)
            break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


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


K = z()
if (K == 1):
    print(1)
    exit()
elif (K % 2 == 0):
    print(-1)
    exit()
elif (K % 5 == 0):
    print(-1)
    exit()
v = '7'
for i in range(1, 10000+1):
    seven = int(v)
    if (seven % K == 0):
        # print(seven)
        print(i)
        exit()
    v = v + '7'

if(is_prime(K)):
    print(K-1)
    exit()
else:
    print(-1)
    exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k = int(input())
seven_list = list()
sum_list = list()
for i in range(10**6):
    sum_list.append(10**i)
    sum_num = sum(sum_list)
    if sum_num >= 10**6:
        break
    if 7*sum_num % k == 0:
        print(i+1)
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#C
def main():
    k = int(input())
    nmax = 15
    qmax = 10**6
    
    if k%2:
        n1 = 0
        n2 = 0
        if k%7==0:
            p = k / 7
            m = 1
            while m<20:
                t = 9 * p * m + 1
                for i in range(nmax):
                    r = t % 10
                    if r<10:
                        if r==0:
                            n1 = i + 1
                        break
                    t /= 10
                m += 1
        
        #if m = 7 * q
        # for q in range(qmax):
        kq = 0
        for j in range(qmax):
            kq = 10 * kq + 9
            if kq%k==0:
                n2 = j + 1
                break
        
        # for q in range(qmax):
        #     t = 9 * k * q + 1
        #     for i in range(nmax):
        #         r = t % 10
        #         if r<10:
        #             if r==0:
        #                 n2 = i + 1
        #             break
        #         t /= 10
        print(n1, n2)
        if n1==0:
            if n2==0:
                print(-1)
                return
            else:
                print(n2)
                return
        if n2==0:
            print(n1)
            return
        if n1<n2:
            print(n1)
        else:
            print(n2)
    
    else:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
K = int(input())
target = 7
lim = 10**6
count = 1
if K % 10 not in [1, 3, 7, 9]:
    print(-1)
while True:
    if ((10**count)-1) % K == 0:
        print(count)
        break
    count+=1

Submission status: Wrong Answer

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

import sys

def main():
    k = int(input())
    mod=999983
    if k % 2==0:
        print(-1)
        exit()
    sevens=7
    for i in range(1,10**6+1):
        if sevens%k==0:
            print(i)
            exit()
        else:
            sevens=(sevens*10+7)%mod
    print(-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
s = "7"
if len(str(N))==1 and N % 2==0:
    print(-1)
else:
    for i in range(10**6):
        s = s + "7"
        if int(s)% N == 0:
            print(len(s))
            break;

Submission status: Wrong Answer

Solution code:
K=int(input())

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

c=0
x=0
Y=x%K

while x<=K:
  x=(7*10**c)+x
  c=c+1

while Y==0:
  Y=x%K
  x=(7*10**c)+x
  c=c+1
  break
else:
  c=-1
  
print(c)

Submission status: Wrong Answer

Solution code:
K = int(input())

keta = len(str(K))
index = 0
for i in range(keta):
    index += 7 * 10 ** i
tmp = 0
count = keta
frag = True
while (True):
    if tmp == index % K:
        frag = False
        break
    if index % K == 0:
        break
    else:
        tmp = index % K
        index = 10 * tmp + 7
        count += 1
if frag == True:
    print(count)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import math

k = int(input())

if k % 2 == 0 or k % 5 == 0:
  ans = -1
elif k == 7:
  ans = 1
elif k == 9:
  ans = 9
else:
  for i in range(1,2000000):
    an = (10 ** i - 1)
    if an % k == 0:
      ans = i
      break

print(ans)

Submission status: Wrong Answer

Solution code:
k = input()
flag = True
for i in k:
	if i != '7':
		flag = False
		break
if flag: print(len(k))
else:
	k = int(k)
	for i in range(1,k+1):
		a = pow(10,i,k) - 1
		if a%9 == 0:
			print(i)
			flag = True
			break
	if not flag: print("-1")

Submission status: Wrong Answer

Solution code:
import sys
K = int(input())
l_begin = 7
count = 1
for i in range(100):
    if l_begin % K == 0:
        print(count)
        sys.exit()
    l_begin = 10 * l_begin + 7
    count += 1
    if K > 10000 and K <= 100000 :
        print(K-1)
        sys.exit()

print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
u = k%10
l =  len(str(k))
if(u == 1):
	print(l*2-2)
elif(u==3):
	print(k-1)
elif (u==9):
	print(l)
else:
	print(-1)

Submission status: Wrong Answer

Solution code:
def multiplier(i):
  cnt = 0
  number = 0
  while cnt <= i:
    number += 10 ** cnt
    cnt += 1
  return number

input_k = int(input())

count = 0
current_7 = 0

if input_k % 2 == 0:
  print("-1")
else:
  while count <= 1000000:


    current_7 = 7 * multiplier(count)
    
    
    if current_7 % input_k == 0:
      print(count-1)
      break
    else:
      count += 1

Submission status: Wrong Answer

Solution code:
k = int(input())

seven = 7
t = 10
c = -1
if k == 7:
    c = 1

for i in range(1000000):
    if seven % k == 0:
        break
    else:
        seven += t * 7
        t *= 10
        c += 1

print(c)

Submission status: Wrong Answer

Solution code:
K=int(input())

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

loop=10**6

for i in range(1, loop, 3):
    a_n=(10**i -1)//9
    a_n*=7

    if a_n%K==0:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
import math

def is_prime_1(num):
    if num < 2:
        return False
    else:
        num_sqrt = math.floor(math.sqrt(num))
        for prime in range(2, num_sqrt + 1):
            if num % prime == 0:
                return False
                break
        return True

K = int(input())
keta = len(str(K))
ans = keta
if K % 2 == 0 or K % 5 == 0:
    print(-1)
elif K % 7 == 0:
    if not is_prime_1(K//7):
        print(-1)
    else:
        M = 3
        while True:
            N = str(K*M//7)
            if set(N) == {"1"}:
                print(len(N))
                break
            else:
                M += 2
else:
    if not is_prime_1(K):
        print(-1)
    else:
        J = 1
        M = 7 *J
        while True:
            N = str(K*M//7)
            if set(N) == {"1"}:
                print(len(N))
                break
            else:
                M += 2

Submission status: Wrong Answer

Solution code:
k = int(input())
if k % 2 == 0:
    print(-1)
elif k ==7:
  	print(1)
else:
  amari = [7]
  tmp = 7
  for i in range(k):
      tmp = (tmp * 10) % k
      if tmp != 7:
          amari.append(tmp%k)
      else:
          break
  amari = amari * ((k//len(amari)) +1)

  ans = amari[0]
  for i in range(1, k+1):
      ans += amari[i]
      if ans % k == 0:
          print(i+1)
          break
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
# sys.setrecursionlimit(100000)


def is_prime(N: int):
    if N == 1:
        return False
    i = 2
    while i * i <= N:
        if N % i == 0:
            return False
        i += 1

    return True


def get_prime(N: int) -> dict:
    if N < 2:
        return {1: 1}
    prime = dict()
    prime[1] = 1

    i = 2
    while i * i <= N:
        while N % i == 0:
            if i in prime.keys():
                prime[i] += 1
            else:
                prime[i] = 1
            N = N // i
        i += 1
    if N != 1:
        prime[N] = 1
    return prime


def main():
    k = int(input().strip())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    if k == 3:
        print(3)
    if is_prime(k):
        ans = k - 1
    else:
        ans = -1

    for i in range(1, 10000):
        n = int("7" * i)
        if n % k == 0:
            print(i)
            return
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())
i = int(str(k)[-1])
result=0
if(i % 2 == 0 | i % 5 == 0 ):
    print(-1)
else:
    numl = [0]*k
    num = 7
    for i in range(k):
        numl[i] = num
        num = 7+ num*10
        
    for i in range(k):
        if(numl[i] % k == 0):
            break
        else:
            result=i+1
    else:
        result = -1
    print(result)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
if(n==1):
  print(-1)
  sys.exit()
for p in range(2, n):
    if n % p == 0:
        print(-1)
        sys.exit()
if(n==2 or n==5):
  print(-1)
  sys.exit()
if(n==7):
  print(1)
  sys.exit()
cnt=1
t="1"
while(1):
  t=t+"1"
  if(int(t) % n ==0):
    print(cnt)
    break
  cnt=cnt+1

Submission status: Wrong Answer

Solution code:
import math
k = int(input())
sevens = []
for i in range(1, 6):
    sevens.append("7"*i)

sevens2 = [int(s) for s in sevens]
ans = []

for i in range(0, len(sevens)):
    if sevens2[i]%k == 0:
        ans.append(i+1)

if ans:
    print(min(ans))
elif k%2 == 0:
    print(-1)
elif k ==5:
    print(-1)
elif k ==9:
    print(-1)
else:
    print(k-1)

Submission status: Wrong Answer

Solution code:
import math
import sys
import copy
input = sys.stdin.readline
 
 
N=int(input())
 
if N==1 or N==7:
    print(1)
elif N%2==0:
    print(-1)

elif N==3:
    print(3)

elif N%5==0:
    print(-1)

elif N==11 or N==77:
    print(2)

elif N==777 or N==37 or N==111 or N==259:
    print(3)
    
elif N==101:
    print(4)

else:
    print(N-1)
    


#print(Wcount,Rcount)

Submission status: Wrong Answer

Solution code:
K = int(input())
# kouho = [int('7' * i) for i in range(1, 1000)]
ans = -1
t = 7
amari = 7 % K
for i in range(1, 1000000):
    t = (t * 10) % K
    a = (t + amari) % K
    if a == 0:
        ans = i + 1
        print(ans)
        exit(0)
    else:
        amari = a
print(ans)

Submission status: Wrong Answer

Solution code:
k=input()
if int(k)%2==0:
    print(-1)
else:
    s='7'
    flag=0
    for _ in range(12):
        if int(s)%int(k)==0:
            flag=1
            print(len(s))
            break
        s=s+'7'
    if flag==0 and k[-1]=='3':
        print(int(k)-1)
    elif flag==0:
        print(-1)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())

if n % 2 == 0 or n % 5 == 0:
    print(-1)
else:
    divisors = make_divisors(n - 1)
    for i in divisors:
        if (10 ** i % n) == 1:
            print(i)
            exit(0)
    print(-1)

Submission status: Wrong Answer

Solution code:
K = str(input())
S = '7'*len(K)
ans = 0

if int(K)%2 == 0 or int(K)%5 == 0:
    ans = 2

while ans == 0:
    if int(S)%int(K) == 0:
        ans = 1
    else:
        S += '7'
    print(len(S))

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

Submission status: Wrong Answer

Solution code:
k = int(input())

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

s = str(k)
l = len(s)

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

print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())

# def is_prime(num):
#     # 2以外の偶数は素数ではないので無視する
#     if num % 2 == 0 and num != 2:
#         return False
    
#     # 繰り返しの上限を半分にする
#     for divisor in range(2, num//2):
#         if num % divisor == 0:
#             return False
            
#     return True

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

# if is_prime(K) and K%3!=0:
#     print(K-1)
#     exit()

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

print(-1)

Submission status: Wrong Answer

Solution code:
import copy

# a = get_int()
def get_int():
    return int(input())

# a = get_string()
def get_string():
    return input()

# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]

# a_list = get_string_list():
def get_string_list():
    return input().split()

# a, b = get_int_multi()
def get_int_multi():  # a, b = get_int_multi()
    return map(int, input().split())

# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    k = get_int()
    ret = -1


    for i in range(1,k*5):
        wk = k * i
        strwk = str(wk)

        if (strwk.count("7") == len(strwk)):
            ret = wk
            break

    print(ret)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
K = int(input())
l_begin = 7
count = 1
for i in range(100):
    if l_begin % K == 0:
        print(count)
        sys.exit()
    l_begin = 10 * l_begin + 7
    count += 1
    if K > 10000:
        print(K-1)
        sys.exit()

print(-1)

Submission status: Wrong Answer

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:
    print(i)
    break
  fav_num +=  7*(10**i)
  i += i + 1

Submission status: Wrong Answer

Solution code:
K = int(input())

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

# Kの桁数
K_str = str(K)
K_len = len(K_str)

for i in range(K_len, K):
    num_str = '7' * i
    num = int(num_str)
    if num % K == 0:
        print(i)
        exit()

print(-1)

Submission status: Wrong Answer

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

if K % 2 == 0:
    print(-1)
elif K % 10 == 5:
    print(-1)
else:
    n = 1
    while True:
        val = sum([ 10**i for i in range(n) ])
        if val % K == 0:
            break
        n += 1
    print(n)

Submission status: Wrong Answer

Solution code:
x=0
input(x)
ans=-1
A='7'
B='7'
for x in range(x-1):
    if(int(A)%x==0):
        ans=int(A)
    A=A+B
print(len(str(ans)))

Submission status: Wrong Answer

Solution code:
k = int(input())

def f(input_, last_amari):
    flag = 0
    if last_amari==-1:
        cost = len(str(input_))
        num = "7" * cost
        amari = int(num) % input_
        if amari % 7 != 0:
            flag = 1
    else:
        cost = len(str(input_)) - len(str(last_amari))
        if cost == 0:
            cost += 1
        num = int(str(last_amari) + ("7"*cost))
        amari = int(num) % input_
    return amari, cost, flag


ans = 0
amari, cost, flag = f(k, -1)
ans += cost 
if flag == 1:
    print("-1")

else:
    while amari !=0:
        amari, cost, flag = f(k, amari)
        ans += cost 
    print(ans)

Submission status: Wrong Answer

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(10000>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: Wrong Answer

Solution code:
import math

def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

def f(x):
    return 7*(10**x-1)//9

K = int(input())
if K == 1 or K==7:
    print(1)
    exit()

if not is_prime(K) or 2<=K<=6:
    print(-1)
    exit()

ans = K-1
print(ans)



# for y in range(10**6):
#     if 9*K*y % 7 != 0:
#         continue
#     t = 9*K*y/7 + 1
#     if t % 10 == 0:
#         a = math.log(t, 10)
#         b = int(a)
#         if a==float(b):
#             ans = b
#             break

Submission status: Wrong Answer

Solution code:
import sys
def resolve():
    K = int(input())
    if K%2 == 0:
        print(-1)
    else:
        nums = [int(''.join(['7']*i)) for i in range(1,K)]
        new_nums = [i for i in nums if i>=K]
        del nums
        for num in new_nums:
            if num%K == 0:
                print(len(str(num)))
                sys.exit()
        print(-1)
resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K=int(input())

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

i=1
seven = "7"

while int(seven)/K!=int(int(seven)/K):
  seven += "7"
  i += 1

print(i)

Submission status: Wrong Answer

Solution code:
k = int(input())
if k % 2 == 0:
    print(-1)
else:
  amari = [7]
  tmp = 7
  for i in range(k+1):
      tmp = (tmp * 10) % k
      if tmp != 7:
          amari.append(tmp%k)
      else:
          break
  amari = amari * ((k//len(amari)) +1)

  ans = amari[0]
  for i in range(1, k+1):
      ans += amari[i]
      if ans % k == 0:
          print(i+1)
          break
  else:
    print(-1)

Submission status: Wrong Answer

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(5000>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: Wrong Answer

Solution code:
k = int(input())
c = 0
a = [0]*(k+1)
a[0] = 7%k

if k%2 == 0 or k%5 == 0:
	print('-1')
elif 7%k == 0:
	print('1')
else:
	for i in range(1,k):
		c += 1
		a[i+1] = (10*a[i] + 7)%k
		if a[i+1] == 0:
			break
	print(c)

Submission status: Wrong Answer

Solution code:
K=int(input())
for i in range(1,100000):
    if list(set(str(K*i)))==["7"]:
        print(len(str(K*i)))
        break
    elif i==9999:
        print("-1")

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
k = ii()

if k%2 == 0 or k%5 == 0:
    print(-1)
else:
    if k%7 == 0:
        k //= 7
    elif k%3 == 0:
        k *= 9
    if k==1:
        print(1)
        exit()
    num = 10
    cnt = 1
    while num != 1:
        num *= 10
        num %= k
        cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
import math

def solution():
    k = int(input())
    n = 1
    divisor = "7"
    while n < k:
        if int(divisor) % k == 0:
            return n
        divisor += "7"
        n += 1
    return -1


solution()

Submission status: Wrong Answer

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 = 50000
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: Wrong Answer

Solution code:
import math

def Repsept():
    
    num = int(input())

    seven_yes = num % 7
    eleven_yes = num % 11
    mod_value = 1

    count = 1
    
    if num % 2 != 0:
    
        if seven_yes == 0 and eleven_yes == 0:
            
        
                while mod_value != 0:
                    value = 7*(pow(10, count)-1)/9
                    
                    mod_value = value % num
        
                    if mod_value != 0:
                        count = count + 1
        
                print(count)
                
        else:
            
            print(num-1)

    else:
    
        print(-1)


def is_prime(n):
    if n == 1: 
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


if __name__ == '__main__':
    Repsept()

Submission status: Wrong Answer

Solution code:
import sys
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

def ans(n):
  if n==1:
    return 1
  if n%2==0 or n%5==0:
    return -1
  if n%7==0:
    return ans(n//7)
  elif N%9==0:
    return lcm(ans3(n),9)
  elif N%3==0:
    return lcm(ans3(n),3)
  else:
    return ans3(n)
def ans3(n):
  r=1
  for i in range(n):
    L.append(r)
    r=(r*10)%n
  return len(set(L))
L=list()
N=int(input())
print(ans(N))

Submission status: Wrong Answer

Solution code:
k = int(input())
if k % 2 == 0:
    print(-1)
elif k > 999983:
    print(-1)
elif k == 999983:
    print(999982)
else:
    flag = True
    for crs in range(1, int(k/2.0+1)):
        f_now = k * crs
        f_now_s = str(f_now)
        b_now = k * (k+1-crs)
        b_now_s = str(b_now)
        if f_now_s.count('7') == len(f_now_s):
            print(len(f_now_s))
            flag = False
            break
        elif b_now_s.count('7') == len(b_now_s):
            print(len(b_now_s))
            flag = False
            break
    if flag:
        print(-1)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
x = len(str(n))
if n % 2==0 or n % 5 ==0:
    print(-1)
    sys.exit()

if n==101:
    print(4)
elif n == 11:
    print(2)
elif n == 7:
    print(1)
else:
    print(n-1)

Submission status: Wrong Answer

Solution code:
k = int(input())

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

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

Submission status: Wrong Answer

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 ** 15
p = X % 2

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

Submission status: Wrong Answer

Solution code:
K = int(input())

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

if K % 7 == 0:
  K //= 7
k = 1
cnt = 1
for i in range(10 ** 8):
  if k % K == 0:
    break
  k = (k * 10 + 1) % K
  cnt += 1
else:
  print(-1)

print(cnt)

Submission status: Wrong Answer

Solution code:
K=int(input())
k=list(str(K))
dic={"1":"7","3":"9","7":"1","9":"3"}
if k[-1] not in dic:
    print(-1)
    exit()
a=7
for i in range(1,K):
    if a%K==0:
        print(i)
        exit()
    a+=7*10**i

Submission status: Wrong Answer

Solution code:
import sys

i0 = float(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 not arr:
        arr.append([n, 1])

    return arr


def seven(j):
    v = "7" * (j + 1)
    v = float(v)
    return v


if i0 % 2 == 0:
    print(-1)
else:
    for i in range(1000000):
        if seven(i) / i0 % 2 == 1.0:
            print(i + 1)
            sys.exit()

Submission status: Wrong Answer

Solution code:
k = int(input())
if k % 2 == 0:
    print(-1)
else:
  amari = [7]
  tmp = 7
  for i in range(k):
      tmp = (tmp * 10) % k
      if tmp != 7:
          amari.append(tmp%k)
      else:
          break
  amari = amari * ((k//len(amari)) +1)

  ans = amari[0]
  for i in range(1, k+1):
      ans += amari[i]
      if ans % k == 0:
          print(i+1)
          break
  else:
    print(-1)