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:
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]

K = int(input())
for i in range(1, 14):
    if K % 2 == 0:
        print('-1')
        break
    lis=make_divisors(int('7'*i))
    if K in lis:
        print(i)
        break
    print(K-1)

Submission status: Wrong Answer

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

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:
k = int(input())

count = 0
ans = 1

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

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
import math

k = int(input())
n = 7
ans = -1

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

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


if k%2==0 or k%5==0:
  ans=-1 
  

  
else:
  for i in range(10**4): #注意
    if n % k  == 0:
      ans = i + 1
      break
    else:
      n =  n*10 + 7

if (k > 10000) and is_prime(k):
  ans = k-1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc174/abc174_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    K = i2n()
    x = 10 % K
    for i in range(1, K + 10):
        if pow(x, i, K) == 1:
            print(i)
            return
    else:
        print(-1)
    return

main()

Submission status: Wrong Answer

Solution code:
k=int(input())
if not k&1:
    print(-1)
    exit()
ks=str(k)
carry=0
d1=int(ks[-1])
i=1
while i<10**7:
    flag=False
    car=int(carry)
    for j in range(0,10):
        if (d1*j+car)%10==7:
            carry=str((car+k*j)//10)
            if len(carry)==carry.count('7'):
                print(i+len(carry))
                exit()
            flag=True
            break
    if not flag:
        print(-1)
        exit()
    i+=1

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 == 0:
			print(i)
			flag = True
			break
	if not flag: print("-1")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
n=int(input())
a=[7]
for i in range(30000):
  a.append(a[-1]*10+7)
if n%2==0 or n%5==0:
  print(-1)
else:
  flg=0
  for i in a:
    if i%n==0:
      print(len(str(i)))
      flg=1
      break
  if flg==0:
    if n%7==0:
      n//=7
      for i in a:
        if i%n==0:
          print(len(str(i)))
          break
    elif n%9==0:
      print(n)
    else:
      f=factorization(n)
      f.sort()
      print(f[-1][0]-1)

Submission status: Wrong Answer

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

flag = [0 for _ in range(k)]
val = 7
cnt = 1
while cnt != 1000000:
  cnt += 1
  val = ((10 * val) % k + 7) % k
  if val == 0:
    break

print(cnt)

Submission status: Wrong Answer

Solution code:
K=int(input())
if(K==7):
    print("1")
elif(K==1):
    print("1")

Submission status: Wrong Answer

Solution code:
k = int(input())

if int(str(k)[0]) % 2 == 0 or k % 2 == 0:
    print(-1)
else:
    num = 7
    c = 1

    while k < 7:
        num = num * 10 + 7
        c += 1

    temp = k
    left = 1

    for i in range(10):
        if str(temp)[0] == '7':
            break

        left += 1
        temp += k

    print(temp)
    print(left)

    while True:
        check = str(temp)
        flag = True
        for i in range(len(check)):
            if check[i] != '7':
                flag = False
                break
        if flag:
            print(temp)
            print(len(check))
            break

        print(temp)

        temp = temp * 10 + k * left
        c += left + 1

Submission status: Wrong Answer

Solution code:
import math

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


def divisor(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


def main():
    n = int(input())
    if n in [1, 7]:
        print(1)
    elif n == 3:
        print(3)
    elif is_prime(n):
        l = sorted(divisor(n-1), reverse=True)
        ans = l[0]
        for i in l[1:]:
            if int('7'*i)%n==0:
                ans = i
        print(ans)
                
    else:
        print(-1)

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=0
l=[]
k=int(input())
if k%2==0:
  print(-1)
else:
  while(1):
    s=s*10+7
    l.append(s)
    if s%k==0:
      print(l.index(s))
      break

Submission status: Wrong Answer

Solution code:

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

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


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

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




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

Submission status: Wrong Answer

Solution code:
from math import log10
n=int(input())
if n<7:
    print(-1)
else:
    k=7
    c=1
    while k%n:
        k=(k%n)*10+7
        c+=1
    print(c)

Submission status: Wrong Answer

Solution code:
K = int(input())
sev = 7
seven = 0
s = 1
if K % 2 ==0:
    seven = 1
    count = -1
KK = K
while seven < 1 :

    while KK <= sev:
        print(KK)
        if sev == KK:
            count = s
            seven = 1
        KK += K*2
    sev = sev * 10 + 7
    s += 1

print(count)

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


n = int(input())

if n % 5 == 0 or n % 2 == 0:
    print(-1)
else:
    if is_prime(n):
        print(n-1)
    else:
        i = '7'
        while True:
            i += '7'
            num = int(i)
            if num % n == 0:
                print(len(i))
                break

Submission status: Wrong Answer

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(10**6):
for i in range(mnum):
    n=int("7"*(i+1))
#    print(n)
    if n%k==0:
        print(i+1)
        exit()
print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K = int(input())

count = 1
prev = [7 % K]
sum = 7 % K
r = 0
while(r not in prev):
    prev.append(r)
    sum += r
    r = 7*(10**(count)) % K
    count += 1
print(count-1 if(sum % K == 0) else -1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc174/abc174_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    K = i2n()
    if K % 7 == 0:
        K = K // 7
    x = 10 % K
    for i in range(1, K + 1):
        if pow(x, i, K) == 1:
            print(i)
            return
    else:
        print(-1)
    return

main()

Submission status: Wrong Answer

Solution code:
k = int(input())
flag = [0 for _ in range(k)]
val = 7
cnt = 1
while cnt != 1000000:
  cnt += 1
  val = ((10 * val) % k + 7) % k
  if val == 0:
    break

if cnt == 1000000:
  print(-1)
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
K = int(input())

def get_primes(N):
    P = []
    M = N
    k_max = int(N**0.5)
    for k in range(2,k_max+1):
        is_next = False
        while not is_next:
            if M % k == 0:
                P.append(k)
                M = M // k
            else:
                is_next = True
    if M != 1:
        P.append(M)
    return P


def check(l):
    return int(l*"7") % K == 0
def check2(l):
    def check2_(K):
        return (K-1) % l == 0
    return check2_
def get_changes(N):
    targets = []
    for p in set(get_primes(N)):
        targets.extend([ i*p for i in range(1,N//p+1) ])
    return targets

K_prime = get_primes(K)

num_3 = sum(map(lambda x:x==3, K_prime))
K_prime_ex = K_prime[num_3:]

if 7 in K_prime_ex:
    K_prime_ex.remove(7)

if 2 in K_prime or 5 in K_prime:
    print(-1)
elif len(K_prime_ex) == 0:
    if num_3 == 0:
        print(1)
    else:
        print(3**num_3)
else:
    target_primes = sorted(list(set(K_prime_ex)))
    if len(target_primes) == 0:
        print(K)
    else:
        ##for l in range(2,K+1):
        targets = []
        for p_ in target_primes:
            targets.append(get_changes(p_-1))
        base = set(targets[0])
        for ref in targets[1:]:
            base = set(ref) & base
        targets = sorted(list(base))

        #print(targets)


        for l in targets:
            if num_3 > 0 and l % num_3 != 0:
                continue
            #check_ = check2(l)
            #print(l, list(map(check_, target_primes)))
            #if any(map(check_, target_primes)) and check(l):
            if check(l):
                print(l)
                break

Submission status: Wrong Answer

Solution code:
K=int(input())
 
if K%2==0:
  print(-1)
else:
  sevens=7
  count=1
  
  while sevens<=K:
    sevens+=7*(10**count)
    count+=1
    
  
  while True:
    if sevens%K==0:
      print(count)
      break
    else:
      sevens+=7*(10**count)
      count+=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 True:


    current_7 = 7 * multiplier(count)
    
    
    if current_7 % input_k == 0:
      print(count-1)
      break
    else:
      count += 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 k  < np.sqrt(777777777777.0):
  for i in range(10**6):
    Moji += '7'
    if int(Moji)%k == 0:
      print(i+1)
      break
      
else:
  print(k-1)

Submission status: Wrong Answer

Solution code:
K = int(input())

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

while True:
    Y = int("".join(map(str,X)))
    if Y % K == 0:
        print(len(X))
        break
    elif K % 2 == 0:
        print(-1)
        break
    elif K % 3 == 0:
        print(-1)
        break
    elif K % 5 == 0:
        print(-1)
        break
    elif K % 13 == 0:
        print(-1)
        break
    elif K % 15 == 0:
        print(-1)
        break
    elif K % 17 == 0:
        print(-1)
        break
    elif K % 19 == 0:
        print(-1)
        break
    elif K % 23 == 0:
        print(-1)
        break
    elif K % 23 == 0:
        print(-1)
        break
    elif K % 29 == 0:
        print(-1)
        break
    else:
        X.append(7)

Submission status: Wrong Answer

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

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):
    ans += amari[i]
    if ans % k == 0:
        print(i+1)
        break
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import math
k = int(input())
sevens = []
for i in range(1, 5):
    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)
else:
    print(k-1)

Submission status: Wrong Answer

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

else:
  i = 0
  tmp_n = 0
  while i >= 0:
    tmp_n = tmp_n + 10**i * 7
 
    # print('tmp_n: ', tmp_n)
    if tmp_n != 0 and tmp_n % K == 0:
      break
    i += 1
    
  print(i)

Submission status: Wrong Answer

Solution code:
K = int(input())

tmp1 = 0
for i in range(1, 2 * K + 1):
    tmp1 += 7 * pow(10, i, K)
    if tmp1 % K == 0:
        print(i)
        exit()

print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
new = [7,77,777,7777,77777,777777,7777777,77777777,777777777]
for i in new[ len(str(k)) : ] :
    if i % k == 0:
        print(new.index(i)+1)
        quit()
    else:
        print("-1")
        quit()

Submission status: Wrong Answer

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

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def isMultiple(s, m):
    tmp = 0
    for i in range(len(s)):
        tmp = (tmp * 10 + int(s[i])) % m
        if tmp == 0:
            return i
    return -1


k = int(readline())
acc = "7" * 50000000
if k % 2 == 0:
    ans = -1
else:

    ans = isMultiple(acc, k) + 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

tmp1 = 0
for i in range(1, 2 * K + 1):
    tmp1 += 7 * pow(10, i, K)
    if tmp1 % K == 0:
        print(i)
        exit()

print(-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
K = int(input())
num = 0
for i in range(10**2):
    num +=7*10**(i)
    if num % K ==0:
        print(i+1)
        exit()
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]

K = int(input())
for i in range(1, 14):
    if K % 2 == 0:
        print('-1')
        break
    lis=[]
    lis.append(make_divisors(int('7'*i)))
    if K in lis:
        print(i)
        break
else:
    print(K-1)

Submission status: Wrong Answer

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

ng = np.array([2,4,5,6,8])

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

a = prime_factorize(x)

if len(set(a) & set(ng))>0:
    print(-1)
else:
    nana = "7"*(len(str(x)))
    while True:
        nana += "7"
        if int(nana)%x ==0:
            break
    print(len(nana))

Submission status: Wrong Answer

Solution code:
K = int(input())
num = 0
K_s = len(str(K))
flg = 0

for i in range(K_s, 10**6):
    if K %2 == 0:
        print(-1)
        break
    num = int(str(1)*i)
    if 7*num % K ==0:
        print(i)
        flg = 1
        break

if flg == 0:
    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 main():
    k = int(input().strip())
    if k % 2 == 0 or k % 5 == 0 or not is_prime(k):
        print(-1)
        return
    if k == 3:
        print(3)

    ans = k - 1

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

K = int(input())

suki = 7
ten = 0
i = 0

if K % 2 == 0:
    print(-1)
    
else:
    
    while suki % K != 0:
        
        ten += pow(10, i)
        i += 1
        suki = 7 * ten
    
    print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
  k = int(input())
  kint = 7 % k
  before = 7 % k
  if k == 1 and k == 7:
    print(1)
    exit()
  for i in range(k):
    x = (before * 10) % k
    before = x
    kint += x
    kint = kint % k
    if kint % k == 0:
      print(i + 2)
      exit()
  print(-1)
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())

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

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

Submission status: Wrong Answer

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

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

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 k  < np.sqrt(7777777777):
  for i in range(10**6):
    Moji += '7'
    if int(Moji)%k == 0:
      print(i+1)
      break
      
else:
  print(k-1)

Submission status: Wrong Answer

Solution code:
k = int(input())

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

Submission status: Wrong Answer

Solution code:
K=int(input())
if K%2==0:
  print(-1)
else:
  x=7%K
  z=7%K
  y=1
  if x==0:
    print(1)
  else:
    while z>0:
      x=(x*10)%K
      z+=x
      z%=K
      y+=1
      if z==0:
        break      
  print(y)

Submission status: Wrong Answer

Solution code:
k = int(input())
i = len(str(k))
cnt = 0
kanou = ["1","3","7","9"]
if (str(k)[len(str(k))-1]) in kanou:
    while True:
        if(int('7'*i))%k==0:
            cnt = 1
            break
        if i>=30:
            break
        else:
            i += 1
    if cnt == 1:
        print(i)
    else:
        if k%7==0 and k%3==0:
            print(k)
        else:
            print(k-1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def main():
  k = int(input())
  kint = 7 % k
  before = 7 % k
  if k == 1:
    print(1)
    exit()
  for i in range(k):
    x = (before * 10) % k
    before = x
    kint += x
    kint = kint % k
    if kint % k == 0:
      print(i + 2)
      exit()
  print(-1)
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
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 ** 6):
        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())

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]

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

tmp = [int('7'*x) for x in range(1,10^3)]

for i in range(len(tmp)):
    if tmp[i] % K == 0:
        print(i+1)
        exit()

Submission status: Wrong Answer

Solution code:
def is_prime(a):
    if a == 1:
        return False
    i = 2
    while i * i <= a:
        if a % i == 0:
            return False
        i += 1
    return True

K = int(input())

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

else:
    print(K - 1)

Submission status: Wrong Answer

Solution code:
k = int(input())

def f(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
u = f(k)

def yakusu(n):
    u = [n]
    i = 2
    while i <= n/2:
        if n%i == 0:
            u.append(i)
        i += 1
    return sorted(list(u))

v = yakusu(k-1)
del v[-1]

if k==1:
    print(1)
elif k%2==0 or len(u)>1:
    print(-1)
else:
    for i in v:
        if int('7'*i)%k==0:
            print(i)
            break
    else:
        print(k-1)

Submission status: Wrong Answer

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

    keta = 1
    N_try = 10 ** 4

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

        else:
            keta += 1
            

    print(-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def isMultiple(s, m):
    tmp = 0
    for i in range(len(s)):
        tmp = (tmp * 10 + int(s[i])) % m
        if tmp == 0:
            return i
    return -1


k = int(readline())
acc = "7" * 8000000
if k % 2 == 0:
    ans = -1
else:

    ans = isMultiple(acc, k) + 1

print(ans)

Submission status: Wrong Answer

Solution code:
k=input()
l=int(k)
s=len(k)
t=k[s-1]
i=1
count=1
j="7"

if t=="0" or t=="2" or t=="4" or t=="5" or t=="6" or t=="8":
    print(-1)
else:
    while(i==1):
        if int(j)%l==0:
            print(count)
            i=0
        else:
            j=j+"7"

Submission status: Wrong Answer

Solution code:
import sys

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

    # for i in range(1000000):
    #     bai = k * i
    #     if (str(bai).count('7') == len(str(bai))):
    #         print(len(str(bai)))
    #         sys.exit()

    # print(-1)

    ans = 0
    if (k % 2 == 0 or k % 10 == 5):
        print(-1)
    elif (k % 10 == 3):
        for i in range(10000000):
            ans = 10 * i + 9
            num = ans * k
            print(len(str(num)))
            if (str(num) == '7' * len(str(num))):
                print(len(str(num)))
                sys.exit()
    elif (k % 10 == 1):
        for i in range(100000):
            ans = 10 * i + 7
            print(ans)
            num = ans * k
            if (str(num) == '7' * len(str(num))):
                print(len(str(num)))
                sys.exit()
    elif (k % 10 == 7):
        for i in range(100000):
            ans = 10 * i + 1
            num = ans * k
            if (str(num) == '7' * len(str(num))):
                print(len(str(num)))
                sys.exit()
    elif (k % 10 == 9):
        for i in range(100000):
            ans = 10 * i + 3
            num = ans * k
            if (str(num) == '7' * len(str(num))):
                print(len(str(num)))
                sys.exit()
                
main()

Submission status: Wrong Answer

Solution code:
def main():
  k = int(input())
  kint = 7 % k
  before = 7 % k
  for i in range(k):
    x = (before * 10) % k
    before = x
    kint += x
    kint = kint % k
    if kint % k == 0:
      print(i + 2)
      exit()
  print(-1)
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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 = fav_num + 10**i
  i = i + 1

Submission status: Wrong Answer

Solution code:
def is_prime(a):
    if a == 1:
        return False
    i = 2
    while i * i <= a:
        if a % i == 0:
            return False
    return True

K = int(input())

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

else:
    print(K - 1)

Submission status: Wrong Answer

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
n=int(input())
a=[7]
for i in range(30000):
  a.append(a[-1]*10+7)
if n%2==0 or n%5==0:
  print(-1)
else:
  flg=0
  for i in a:
    if i%n==0:
      print(len(str(i)))
      flg=1
      break
  if flg==0:
    if n%9==0:
      print(n)
    else:
      f=factorization(n)
      f.sort()
      print(f[-1][0]-1)

Submission status: Wrong Answer

Solution code:
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

K = int(input())
seven=0

i=0
seven_mod=0
while True:
    i+=1
    
    seven_mod = (seven_mod + 7%K * power_func(10,i,K))%K
    if seven_mod == 0:
        break
    
print(i)

Submission status: Wrong Answer

Solution code:
n =int(input())
if n%2==0:
    print(-1)
elif n==1:
    print(1)
else:
    ans =1
    start = 7
    while True:
        start = ((start%n*10%n)+7)%n
        #start = start%n
        #print(start)
        if start ==0:
            ans+=1
            print(ans)
            break
        if ans>=1000000:
            print(-1)
            break
        ans+=1

Submission status: Wrong Answer

Solution code:
k=int(input())
keta=str(k)
s=int("7"*len(keta))
a=-1
if k%2==0:
	print(a)
else:
	for x in range(len(keta),len(keta)+1000):
		if s%k==0:
			a=x
			break
		else:
			s=str(s)+"7"
			s=int(s)
	if a==-1:
		a=k-1
	print(a)

Submission status: Wrong Answer

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

ng = np.array([2,4,5,6,8])

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

a = prime_factorize(x)

if len(set(a) & set(ng))>0:
    print(-1)
elif len(set(a))== 1 and len(str(x))>3:
    nana = "7"*(x)
    while True:
        nana = nana[:len(nana)-1]
        if int(nana)%x ==0:
            break
    print(len(nana))
else:
    nana = "7"*(len(str(x)))
    while True:
        nana += "7"
        if int(nana)%x ==0:
            break
    print(len(nana))