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:
K = int(input())
cnt=len(str(K))

if K % 2 == 0:
    print(-1)
else:
    while True:
        n = int(cnt*str(1))
        if n % int(K) != 0:
            cnt+=1
        else:
            print(len(str(n)))
            break

Submission status: Wrong Answer

Solution code:
k=int(input())
z=-1
r=((10**(k))-1)*7//9
q=((10**(k-1))-1)*7//9
if r%k==0:
    print (k)
elif r%k==0:
    print (k-1)
for i in range (k):
    d=((10**(i+1))-1)*7//9
    if d%k==0:
        z=i+1
        break
print(z)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


k = I()

m = k % 10
if m % 2 == 0 or m == 5:
    print(-1)
    exit()
elif k == 1:
    print(1)
    exit()
else:
    s = "1"
    rk = 1
    for i in range(1, 10 ** 6 + 1):
        rk1 = ((10 % k) * rk + 1) % k
        if rk1 == 0:
            print(i + 1)
            exit()
        rk = rk1

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

Solution code:
n=int(input())

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

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

#print(lcm(n, 7)//7)
n1=(n // math.gcd(n, 7))

if n>1000:
  print(n-1)
  exit()
ii=1
jj=1
for kk in range(n):
	if ii%n1==0:
		print(jj)
		exit()
	ii=10*ii+1
	jj+=1

Submission status: Wrong Answer

Solution code:
print(999983 * 7) 
print(999983 * 17)
print(999983 * 817)
print(999983 * 5817)
print(999983 * 75817)
print(999983 * 875817)
print(999983 * 3875817)
print(999983 * 23875817)

Submission status: Wrong Answer

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

Solution code:
k=int(input())
if k%2==0 or k%5==0:
  print("-1")
else:
  a=len(str(k))
  s=a
  t=0
  for i in range(a):
    t=t+7*10**i
  
  for w in range(a,k):
    t=t+7*10**w
    if t%k==0:
      s=w
      break
    
  print(s+1)

Submission status: Wrong Answer

Solution code:
from math import gcd
def prime_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())
if k in [2,5]:
    print(-1)
if k%7==0:
    k//=7
if len(prime_factorization(k))>=2:
    print(-1)
x = 1
num = 1
while True:
    if num%k==0:
        print(x)
        exit()
    num += 10**x
    x += 1

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 = 1
        while True:
            N = str(K*M//7)
            if set(N) == {"1"}:
                print(len(N))
                break
            else:
                M += 10
else:
    if not is_prime_1(K):
        print(-1)
    else:
        J = 1
        while True:
            M = 7*J
            N = str(K*M//7)
            if set(N) == {"1"}:
                print(len(N))
                break
            else:
                J += 2

Submission status: Wrong Answer

Solution code:
K = int(input())

if K % 2 == 0:
    print(-1)
    exit()
k= str(K)
leng = len(k)

for i in range(leng, K):
    nstr = '7' * i
    n = int(nstr)
    if n % K == 0:
        print(i)
        exit()

print(-1)

Submission status: Wrong Answer

Solution code:
k=int(input())
mod7 = 7%k
mod10= 10%k

mod = mod7
mod10times = mod7

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

for i in range(2,2000000):
    mod10times = mod10times*mod10%k
    mod = mod10times+mod%k
    
    if  mod%k==0:
        print(i)
        break
        
print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, re
import math
import numpy as np
from decimal import Decimal
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

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()))
sys.maxsize = 10 ** 15
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

k = INT()
s = 0

if k % 2 == 0 or k % 5 == 0 or k < 7 or k > 1000000 - 7:
    print("-1")
elif k == 7:
    print("1")
elif k == 9:
    print("9")
else:

    def Soroeru(a, b):
        global s
        s = a * b
        num = str(s)
        if num[-1] != "7" or num[-1] != num[-2]:
            Soroeru(a, b + 1)

    Soroeru(k, 1)

    def A(a):
        ans = True
        for x in str(a):
            if x != "7":
                ans = False
                break
        if ans:
            print(len(str(a)))
        else:
            A(a * 101)
    A(s)

Submission status: Wrong Answer

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

r = 7 % K
dict = defaultdict(bool)  # int/bool/list....
dict[r] = True
orgr = r
d = 1
# while r > 0:
for _ in range(2 * K):
    d += 1
    r = (10 * r + 7) % K
    if dict[r]:
        # if r == orgr:
        print(-1)
        sys.exit()
    dict[r] = True
    if r == 0:
        print(d)
        break

Submission status: Wrong Answer

Solution code:
#from math import *
from collections import *
from random import *
from bisect import *
import sys
input=sys.stdin.readline
def lis():
    return list(map(int,input().split()))
def ma():
    return map(int,input().split())
def inp():
    return int(input())
n=inp()
if(n%2==0 or n%5==0):
    print(-1)
    exit(0)
co=1
if(7%n==0):
    print(1)
    exit(0)
while(1):
    gp=10*(pow(10,co,n)-1)
    gp=gp%n
    gp=gp*pow(9,n-2,n)
    gp+=1
    gp=7*gp
    gp=gp%n
    if(co>10000000):
        co=-2
        break
    if(gp%n==0):
        break
    co+=1
print(co+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 == 2 or k % 10 == 4 or k % 10 == 5 or k % 10 == 6 or k % 10 == 8 or k % 10 == 0:
        print(-1)
        exit()
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            else:
                num = tmp // 10 % 10 - 7
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 5 * 10 ** 7:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K = int(input())
from math import gcd

last = int(str(K)[-1])

if last not in [1, 7, 3, 9]:
    print(-1)
    exit()

if list(set(list(str(K)))) == [7]:
    print(len(K))
    exit() 

STR = 7
for n in range(1, 10 ** 5):
    if gcd(STR, K) == STR:
        print(n)
        exit()
    
    STR *= 10
    STR += 7

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(13000>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())
f=-1
for i in range(1,1000):
    s=k*i
    l=len(str(s))
    for i in range(l):
        if str(s).count('7')==l:
            f=l
            break
print(f)

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
    counter=1
    for i in range(1,10**6+1):
        if sevens%k==0:
            print(counter)
            exit()
        else:
            sevens=(sevens*10+7)%mod
            counter+=1

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())

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

tmp = 7
for i in range(1, k):
    tmp = (10 * tmp) % k
    if tmp == 7:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
K = int(input())
if K == 2 or K ==5:
  print(-1)
  exit()
if K in [101,11,707,77]:
  print(4)
  exit()
if K in [3,37,21,259]:
  print(3)
  exit()
if K in [41,271,287,1897]:
  print(5)
  exit()
if K in [239,4649,1673,32543]:
  print(7)
  exit()
if K in [1,7]:
  print(1)
  exit()
print(K-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()
p = [i for i in str(n)]
y = list(set(p))
y.sort()
if (len(y)==1 and y[0]=="1") or n % 7==0:
    print(x)
elif "10"*(x//2)+"1"==str(n):
    print(x+1)
else:
    print(n-1)

Submission status: Wrong Answer

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

Moji = ''
if k % 2 ==0:
  print(-1)
elif str(k)[0] == 5:
  print(-1)
elif np.int64(k)  < np.sqrt(7777777777.0):
  for i in range(100):
    Moji += '7'
    if np.int64(int(Moji))% np.int64(k) == 0:
      print(i+1)
      break
      
else:
  print(k-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
i = 0
y = 0
if K%2 == 0 or K%5 == 0:
  print(-1)
elif K%3 == 0:
  print(3)
else:
  if K%7 == 0:
    K = K//7
  while True:
    i += 1
    y += 10**(i-1)
    if y%K== 0:
      break
  print(i)

Submission status: Wrong Answer

Solution code:
k=int(input())
mod7 = 7%k
mod10= 10%k

mod = mod7
mod10times = mod7

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

for i in range(2,1000000):
    mod10times = mod10times*mod10%k
    mod = mod10times+mod%k
    
    if  mod%k==0:
        print(i)
        break
        
print(-1)

Submission status: Wrong Answer

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

@author: aruto
"""

import math

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]

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

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

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

elif N == 1:
    print(1)

else:
    a = 1
    i = 1
    
    A = factorization(N)
    
    g = 1
    
    for n in A:
        if n[0] == 3:
            k_f = 3
        else:
            N = n[0]*9
            K = make_divisors(n[0]-1)
            for k in reversed(K):
                a = power_func(10,k,N)-1
                if a == 0:
                    k_f = k
        g = g*k_f*n[0]**(n[1]-1)//math.gcd(g,k_f*n[0]**(n[1]-1))
    print(g)

Submission status: Wrong Answer

Solution code:
#from math import *
from collections import *
from random import *
from bisect import *
import sys
input=sys.stdin.readline
def lis():
    return list(map(int,input().split()))
def ma():
    return map(int,input().split())
def inp():
    return int(input())
n=inp()
if(n%2==0 or n%5==0):
    print(-1)
    exit(0)
co=1
if(7%n==0):
    print(1)
    exit(0)
while(1):
    gp=10*(pow(10,co,n)-1)
    gp=gp%n
    gp=gp*pow(9,n-2,n)
    gp+=1
    gp=7*gp
    gp=gp%n
    if(co>3000000):
        co=-2
        break
    if(gp%n==0):
        break
    co+=1
print(co+1)

Submission status: Wrong Answer

Solution code:
k=int(input())
if k%10 in [2,4,5,6,8,0]:
  print(-1)
  exit()
  
for i in range(1,10000):
  tmp=7*(10**i-1)//9
  if tmp%k==0:
    print(i)
    exit()
print(k-1)

Submission status: Wrong Answer

Solution code:
#abc174 c
Ks = input()
NGlist = ['0','2','4','5','6','8']
if Ks[-1] in NGlist:
    print(-1)
else:
    Ks = int(Ks)
    cnt =1
    num =7
    if Ks == 7:
        print(1)
        exit()
    while True:
        cnt +=1
        num = 10*num+7
        if num % Ks == 0:
            
            print(cnt)
            exit()

Submission status: Wrong Answer

Solution code:
k = int(input())

ans = 0
if k == 7:
    ans = 1
elif k % 2 == 0:
    ans = -1
else:
    for i in range(1, (len(str(k)) * 7) + 1):
        tgt = int("7" * i)
        if tgt % k == 0:
            ans = i
            break
    if ans == 0:
        ans = -1

print(ans)

Submission status: Wrong Answer

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

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

if k == 7:
    print(1)

n = 0
for i in range(1, k):
    n = n*10 + 1
    if n % k == 0:
        print(i)
        exit()
    t2 = time.time()
    if t2 - t1 > 1.5:
        print(k-1)
        exit()

Submission status: Wrong Answer

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

r = 7 % K
dict = defaultdict(bool)  # int/bool/list....
dict[r] = True
orgr = r
d = 1
# while r > 0:
for _ in range(2 * K):
    d += 1
    r = (10 * r + 7) % K
    if dict[r]:
        # if r == orgr:
        print(-1)
        sys.exit()
    if r == 0:
        print(d)
        break


# print(d)

Submission status: Wrong Answer

Solution code:
n = int(input())
nl = len(str(n))

if n==999983:
    print(999982)
else:
    for i in range(nl, 10000):
        nana = int('7' * i)
        
        if nana % n == 0:
            print(i)
            break
    else:
        print(-1)

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 = 1
        while True:
            N = str(K*M//7)
            if set(N) == {"1"}:
                print(len(N))
                break
            else:
                M += 10
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:
                J += 2

Submission status: Wrong Answer

Solution code:
k = int(input())
sevens = 7
exist = False

if k % 2 == 0:
  exist = False
elif k % 5 == 0:
  exist = False
elif k % 7 == 5:
  exist = True
  sevens = pow(10,k-2)
else:
  for i in range(1000000):
    if sevens % k == 0:
      exist = True
      break
    sevens = sevens * 10 + 7

if exist:
  print(len(str(sevens)))
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

K = int(input())
if K%5==0 or K%2==0:
    print(-1)
elif K==7:
    print(1)
else:
    if len(list(set(str(lcm(11,K)))))==1:
        print(len(str(lcm(11,K))))
    else:
        print(K-1)

Submission status: Wrong Answer

Solution code:

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
k = int(input())
# if  k%2==0 or k%5==0:
#     print(-1)
# else:
#     se = prime_factorize(k)
#     k_ = k
#     if not 7 in se:
#         k_ = k*7

#     K = int(str(k_)[-1])
#     # print(K)
#     if K==1:
#         # print("a")
#         x = 7
#     elif K==3:
#         x=9
#     elif K==7:
#         x = 1
#     elif K==9:
#         x = 3
#     z = 0
#     # print(x)
#     while True:
#         s = 10*z + x
#         q = k_ * s
#         # print(q)
#         if str(q)=="7"*len(str(q)):
#             print(len(str(q)))
#             break
#         z+=1
#         # if  z==10:
#         #     break

sen = []
for i in range(1,k*3):
    s =int("7"*i)
    sen += prime_factorize(s)
sen = set(sen)

z = prime_factorize(k)
m = True
for i in z:
    if i in sen:
        m = False
if  k%2==0 or k%5==0:
    print(-1)
elif m:
    print(k-1)
else:
    w = len(str(k))
    # yaku = prime_factorize(k)
    while True:
        s = "7"*w
        if int(s)%k==0:
            print(w)
            break
        w+=1

Submission status: Wrong Answer

Solution code:
import numpy as np
k = np.int64(int(input()))

Moji = ''
if k % 2 ==0:
  print(-1)
elif str(k)[0] == 5:
  print(-1)
elif k  < np.sqrt(7777777777.0):
  for i in range(50):
    Moji += '7'
    if np.int64(int(Moji))%k == 0:
      print(i+1)
      break
      
else:
  print(k-1)

Submission status: Wrong Answer

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

    if i == n-1:
        print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
if k % 2 == 0:
  print(-1)
elif k % 5 == 0:
  print(-1)
else:
  for i in range(1, k):
      n = "7"*i
      if int(n) % k == 0:
          print(i)
          break

Submission status: Wrong Answer

Solution code:
k=int(input())
ans=1
judge=0
remainder=7%k

while ans<=k:
    if remainder==0:
        judge=1
        break
    else:
        remainder=remainder*10+7
        ans+=1
        
if judge==1:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 == 2 or k % 10 == 4 or k % 10 == 5 or k % 10 == 6 or k % 10 == 8 or k % 10 == 0:
        print(-1)
        exit()
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            else:
                num = tmp // 10 % 10 - 7
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 5 * 10 ** 7:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 5 * 10 ** 7:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 5 * 10 ** 7:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            ans += 1
            if ans > 5 * 10 ** 7:
                print(-1)
                break
            """
                num = 7
            elif 10 - (tmp // 10) % 10 == 3:
                num = 9
            elif 10 - (tmp // 10) % 10 == 7:
                num = 1
                print(tmp)
            elif 10 - (tmp // 10) % 10 == 9:
                num = 3
            else:
                print(-1)
                break
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            print(tmp)
            ans += 1
            """


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
K = int(input())

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


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())
if K in [101,11,707,77]:
  print(4)
  exit()
if K in [3,37,21,259]:
  print(3)
  exit()
if K in [41,271,287,1897]:
  print(5)
  exit()
if K in [239,4649,1673,32543]:
  print(7)
  exit()
if K in [1,7]:
  print(1)
  exit()
print(K-1)

Submission status: Wrong Answer

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

if k == 7:
    ans = 1
elif k % 2 == 0:
    ans = -1
else:
    i = 1
    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: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

#k = int(input())
for k in range(1, 100):
    if k == 7 or k == 1:
        print(k, 1)
    elif k % 2 == 0 or k % 5 == 0: print(k, -1)
    else:
        if k % 7 == 0: k = k // 7
        mod = 9*k
        i = 1;
        result = 10;
        while result != 1:
            result = (result * 10) % mod
            i += 1
        print(k, i)

Submission status: Wrong Answer

Solution code:
k=input()
if int(k)%2==0:
    print(-1)
else:
    s='7'
    flag=0
    for _ in range(20):
        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:
k = int(input())
if 7%k==1:
  print(1)
elif k%2==0:
  print(-1)
else:
  cnt = 1
  pre = 7
  while(True):
    surp = (pre*10+7)%k
    cnt += 1
    if surp==0:
      break
    if cnt>1000000:
      cnt = -1
      break
    pre = surp
  print(cnt)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np

k = int(input())

s = 0
cnt = 0
flg = False

while (cnt < 1e7):
    cnt += 1
    print(cnt)
    s = s * 10 + 7 
    # print(s)

    if s % k == 0:
        flg = True
        break

    if k < 7:
        flg = False
        break

    if k % 2 == 0:
        flg = False
        break


if flg == True:
    print(cnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
K = int(input())
i = 0
n = 0
  
while n <= 10**7:
  n += 7 * (10**i)
  i += 1
  if n % K == 0:
    print(i)
    break
  elif K % 2 == 0:
    print("-1")
    break
  elif K == 999983:
    print("999982")
    break
  else:
    pass

Submission status: Wrong Answer

Solution code:
import numpy as np
k = np.int64(int(input()))

Moji = ''
if k % 2 ==0:
  print(-1)
elif str(k)[0] == 5:
  print(-1)
elif k  < np.sqrt(7777777777.0):
  for i in range(20):
    Moji += '7'
    if np.int64(int(Moji))%k == 0:
      print(i+1)
      break
      
else:
  print(k-1)

Submission status: Wrong Answer

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

r = 7 % K
# dict = defaultdict(bool)  # int/bool/list....
# dict[r] = True
orgr = r
d = 1
# while r > 0:
for _ in range(K + 1):
    d += 1
    r = (10 * r + 7) % K
    # if dict[r]:
    if r == 0:
        print(d)
        break
    if r == orgr:
        print(-1)
        sys.exit()

# print(d)

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

def check(x):
    cnt = 0
    while x > 0:
        x, m = divmod(x, 10)
        if m != 7:
            return 0
        cnt += 1
    return cnt

K = INT()

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

cur = K
for i in range(10000000):
    res = check(cur)
    if res:
        print(res)
        break
    cur += K
else:
    print(-1)