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())
D = [0]* (10**7)
a=0

for i in range(1,10*7):
    D = int(('7')*i)
    
    if D % K == 0:
        b=i
        a=1
        break

if a==1:
    print(b)
else:
    print('-1')

Submission status: Wrong Answer

Solution code:
K = int(input())

L = 9*K
s = 1

for i in range(1, 9*(10**6)+1):
  s = s*10%L
  if s == 1:
    print(i)
    exit()

print("-1")

Submission status: Wrong Answer

Solution code:
a = int(input())

if a %2 ==0:
  print(-1)
else:
  n = 7
  ans = [0]
  for i in ans:
    if n % a == 0:
      print(ans[-1])
    else:
      ans.append(i + 1)
      n += 7 * 10**ans[-1]

Submission status: Wrong Answer

Solution code:
N = int(input())
a=0
flag=0
print("N=",N)
for i in range(1,N+1):
    a+=(7*10**(i-1))%N
    if a>N:
        a-=N
    if a==N:
        a=0
    if a==0:
        print(i)
        flag=1
        break
if flag==0:
    print(-1)

Submission status: Wrong Answer

Solution code:
s = int(input())
su = 0
sum = []
for i in range(0,s):
    su=su*10+7
    if su not in sum:
        sum.append(su)
for i in range(len(sum)):
    if sum[i]%s==0:
        print(sum[i])
        exit()
for i in sum:
    if i%s !=0:
        continue
print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x=int(input())

def mult(x):
    t=str(7)*(length(x))
    if length(x)<len(t) and x <= int(t):
        print(len(t))
    else:
        t=str(7)*(length(x)+1)
        print(len(t))

def length(x):
    if x==0:
        return 0
    if x<0:
        return length(x*(-1))
    elif x < 10:
        return 1
    else:
        return 1+(length(x // 10))

mult(x)

Submission status: Wrong Answer

Solution code:
x=int(input())

def mult(x):
    t=str(7)*(length(x))
    if length(x)<=len(t) and x <= int(t):
        print(len(t))
    else:
        t=str(7)*(length(x)+1)
        print(len(t))

def length(x):
    if x==0:
        return 0
    if x<0:
        return length(x*(-1))
    elif x < 10:
        return 1
    else:
        return 1+(length(x // 10))

mult(x)

Submission status: Wrong Answer

Solution code:
x=int(input())

def mult(x):
    t=str(7)*(length(x))
    if length(x)<=len(t) and x <= int(t):
        print(t)
    else:
        t=str(7)*(length(x)+1)
        print(t)

def length(x):
    if x==0:
        return 0
    if x<0:
        return length(x*(-1))
    elif x < 10:
        return 1
    else:
        return 1+(length(x // 10))

mult(x)

Submission status: Wrong Answer

Solution code:
k = int(input())

flag = False

resid  = 7
if k == 7:
    i = -1
    flag = True
else:
    for i in range(k):
        resid = (resid*10+7)%k
        if resid == 0:
            flag = True
            break

if flag:
    print(i+2)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())

ans = 1
mod = 7

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

if mod % k == 0:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())

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

elif (K%10) % 5 == 0:
    pass
    print(-1)
else:
    num = 7
    for i in range(K-1):
        if num % K == 0:
            print(str(i+1))
            break
        num = num *10 + 7
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
sevens = []
for i in range(7):
    string = '7'*(i+1)
    print(string)
    sevens.append(int(string))

cnt = 1
a = -1
while K*cnt < 10**6:
    num = K*cnt
    if num in sevens:
        a = len(str(num))
        break
    cnt += 1
print(a)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    K = int(input())
    
    if K%2==0 or K%5==0:
        print(-1)
        return
    
    if K % 7:
        L = 9*K
    else:
        L = 9*K//7
    a = 1
    for i in range(1,K):
        a = (a * 10) % L
        if a == 1:
            print(i)
            return
    print(-1)
main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
K = int(input())
res = 0

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

surplus = 1
while True:
    res += 1
    surplus = (10 * surplus) % (9*K)
    if surplus == 1:
        break

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k =int(input())

if k % 2 == 0 or k % 5 == 0:
  print(-1)
else:
  i = 1
  num = 10
  while num % k != 1:
    num %= k
    num *= 10
    i += 1
  print(i)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# from typing import *


# def solve(K: int) -> int:
def solve(K):
    if K == 1:
        return 1
   
    if K < 7:
        return -1

    curr = 7 % K
    for i in range(1, 10**6 + 1):
        if curr == 0:
            return i

        curr *= 10
        curr += 7
        curr %= K

    return -1


# generated by online-judge-template-generator v4.4.0 (https://github.com/kmyk/online-judge-template-generator)
def main():
    K = int(input())
    a = solve(K)
    print(a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# from typing import *


# def solve(K: int) -> int:
def solve(K):
    if K < 7:
        return -1

    curr = 7 % K
    for i in range(1, 10**6 + 1):
        if curr == 0:
            return i

        curr *= 10
        curr += 7
        curr %= K

    return -1


# generated by online-judge-template-generator v4.4.0 (https://github.com/kmyk/online-judge-template-generator)
def main():
    K = int(input())
    a = solve(K)
    print(a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())
x = 0
i = 1
mx = []
while (True):
  x = 10 * x + 7
  m9 = x % 9
  mk = x % k
#  print("x, mx, mk, m9 = ", x, mx, mk, m9)
  if m9 in mx:
    print(-1)
    break
  if mk == 0:
    print(i)
    break
  mx.append(m9)
  i += 1

Submission status: Wrong Answer

Solution code:
k = int(input())
x = 0
i = 1
mx = []
while (True):
  x = 10 * x + 7
  m9 = x % 9
  mk = x % k
  print("x, mx, mk, m9 = ", x, mx, mk, m9)
  if m9 in mx:
    print(-1)
    break
  if mk == 0:
    print(i)
    break
  mx.append(m9)
  i += 1

Submission status: Wrong Answer

Solution code:
K = int(input())

mod_ini = 7%K
mod = 0
cnt = 0

while True:
    if K%2 != 0:
        print(-1)
        break
    
    cnt += 1
    mod = (mod*10 + 7)%K
    #print(mod)
    
    if mod == 0:
        print(cnt)
        break
    elif mod == mod_ini and cnt != 1:
        print(-1)
        break

Submission status: Wrong Answer

Solution code:
K=int(input())
n = 0
seven=7
while n<=K:
    seven += ((7*10)*n)
    if seven%K==0:
        print(n)
        break
    if n ==K:
        if seven%K==0:
            print(n)
        else:
            print(-1)
    n +=1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
k=int(input())
h=10**6
s=7
for i in range(1,h):
  m=s%k
  if m==0:
    print(i)
    break
  s=m*10+7

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
k=int(input())
s=7
for i in range(1,k):
  m=s%k
  if m==0:
    print(i)
    break
  s=m*10+7

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
from math import log10
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    K = int(input())
    mink = int(log10(K))
    sevens = 7 
    for i in range(mink+1, K):
        if sevens%K==0:
            print(len(str(sevens)))
            quit()
        sevens = sevens*10+7
    print(-1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    K = int(input())
    sevens = 7 
    for i in range(1, K):
        if sevens%K==0:
            print(len(str(sevens)))
            quit()
        sevens = sevens*10+7
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    K = int(input())
    if K % 2 == 0:
        print(-1)
        return
    else:
        x = 7 % K
        for i in range(1, K+1):
            if x == 0:
                print(i)
                return
            x = (x*10+7) % K


if __name__ == '__main__':
    main(sys.stdin.readline, print)

Submission status: Wrong Answer

Solution code:
K = int(input())

seven = "7"
flag = 1

if K%2==0:
	print(-1)
	
else:
	for i in range(1,10000):
		if int(seven*i) % K == 0:
			print(i)
			flag=0
			break
	
	if flag:
		print(-1)

Submission status: Wrong Answer

Solution code:
k=int(input())
n=10**6

if k%2==0 or k%5==0:
    print(-1)
else:
    for i in range(1,n):
        if (10**i) % k==1:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
k=int(input())
n=10**6

if k%2==0 or k%5==0 or k<7:
    print(-1)
else:
    for i in range(1,n):
        if (10**i-1) % k==0:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
K = int(input())

seven = "7"
flag = 1

for i in range(1,10000):
	if int(seven*i) % K == 0:
		print(i)
		flag=0
		break

if flag:
	print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())

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

print(res)

Submission status: Wrong Answer

Solution code:
K = int(input())

seven = "7"

for i in range(1,10000):
	if int(seven*i) % K == 0:
		print(i)
		break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# import sys
# input = sys.stdin.readline
import itertools
import collections
from decimal import Decimal


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    n = int(input())
    nana = 7
    for i in range(n-1):
        if nana % n == 0:
            print(i+1)
            exit()
        nana = (nana * 10 + 7) % n
    print(-1)

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

def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# import sys
# input = sys.stdin.readline
import itertools
import collections
from decimal import Decimal


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    n = int(input())
    nana = 7
    if n % 2 == 0:
        print(-1)
        exit()
    for i in range(n-1):
        if nana % n == 0:
            print(i+1)
            exit()
        nana = (nana * 10 + 7) % n
    print(-1)

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

def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# import sys
# input = sys.stdin.readline
import itertools
import collections
from decimal import Decimal


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    n = int(input())
    nana = 7
    if n % 2 == 0:
        print(-1)
        exit()
    for i in range(n-1):
        print(nana)
        if nana % n == 0:
            print(i+1)
            exit()
        nana = (nana * 10 + 7) % n
    print(-1)

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

def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# import sys
# input = sys.stdin.readline
import itertools
import collections
from decimal import Decimal


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    n = int(input())
    nana = 7
    for i in range(n-1):
        print(nana)
        if nana % n == 0:
            print(i+1)
            exit()
        nana = (nana * 10 + 7) % n
    print(-1)

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

def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
K = int(input())
if K%7 == 0:
  L = 9*K//7
else:
  L = 9*K

if K%2 == 0 or K%5 == 0:
  print(-1)
else:
  X = 10%L
  for i in range(K):
    X = X*10 % L
    if X == 1:
      print(i+2)
      break

Submission status: Wrong Answer

Solution code:
K = int(input())
if K%7 == 0:
  L = 9*K//7
else:
  L = 9*K

if L%2 == 0 or L%5 == 0:
  print(-1)
else:
  X = 10%L
  for i in range(K):
    X = X*10 % L
    if X == 1:
      print(i+2)
      break

Submission status: Wrong Answer

Solution code:
K = int(input())
if K%7 == 0:
  L = 9*K/7
else:
  L = 9*K

if L%2 == 0 or L%5 == 0:
  print(-1)
else:
  X = 10%L
  for i in range(K):
    X = X*10 % L
    if X == 1:
      print(i+2)
      break

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

k = inp()

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

print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())
l = [0 for i in range(K)]
r = 0
for i in range(K):
    if i == 0:
        if 7%K == 0:
            print(1)
            break
        else:
            r = 7%K
            l[r] = 1
    else:
        r = (10*r+7)%K
        if r == 0:
            print(i+1)
            break
        elif l[r] != 0:
            print(-1)
            break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# C - Repsept
def main():
    K = int(input())
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return

    cnt = 0
    while cnt <= K:
        cnt += 1
        if int("7" * cnt) % K == 0:
            print(cnt)
            break
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
K = int(input())
mod = 0
# mod Kは、0,1,...,K-1　の高々K種類
# i=K+1 まで行くと鳩の巣原理よりmodが既出になり、以降ループ
# すなわちi=Kまで見れば十分
for i in range(1, K + 1):
    mod = (10 * mod + 7) % K
    if mod % K == 0:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

k=int(input())

if k%2==0 or k%5==0:
    print(-1)
else:
    # if k%7==0:
    #     k//=7
    tmp=1
    cnt=1
    k*=9
    while (tmp*10-1)%k:
        tmp*=10
        tmp%=k
        cnt+=1
    print(cnt)

Submission status: Wrong Answer

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

i = 7
cnt = 1
while i != 0:
    i = i * 10 + 7
    i %= 7
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
if k % 7 == 0: k // 7
k *= 9
i = 10 % k
cnt = 1
while i != 1:
    i = i * 10 % k
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
k = int(input())
if k % 2 * k % 5 == 0:
    print(-1)
    exit()
if k % 7 == 0: k // 7
k *= 9
i = 10 % k
cnt = 1
while i != 1:
    i = i * 10 % k
    cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
K = int(input())

a = 7

for i in range(1, K):
    if a % K == 0:
        print(i)
        break
    a = (10 * a + 7) % K
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())

a = 7

for i in range(1, K):
    if a % K == 0:
        print(i)
        break
    else:
        a = (10 * a + 7) % K

Submission status: Wrong Answer

Solution code:
K = int(input())
x = 7 % K #mod(K)
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
i = 0
while i < K:
  ans += 1
  x = (x * 10 + 7) % K
  
  if x == 7 % K:
    print('-1')
    exit()
  if x == 0:
    print(ans)
    exit()
  i += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K = int(input())
x = 7 % K #mod(K)
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
i = 1
while i < K:
  ans += 1
  x = (x * 10 + 7) % K
  
  if x == 7 % K:
    print('-1')
    exit()
  if x == 0:
    print(ans)
    exit()
  i += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k=int(input())
num=7%k
ans=-1

if k%2==0 or k%5==0:
	ans=-1
else:
	for i in range(1,k):
		# print(num)
		if num==0:
			ans=i
			break
		num=(num*10+7)%k

print(ans)

Submission status: Wrong Answer

Solution code:
k = int(input())

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

if k == 1:
    print(1)
    exit()

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

print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
s = 7
ans = 1
while ans < 10 ** 6:
    if s % k == 0:
        print(ans)
        break
    s = s * 10 + 7
    ans += 1
print(-1)

Submission status: Wrong Answer

Solution code:
import sys

K = int(input())
if(K%7==0):
  L = 9*K/7
else:
  L = 9*K
  
max_n = 1000005
ans = 0
if(L%2==0) and (L%5==0):
  print(-1)
  sys.exit()
else:
  amari = 10%L
  for k in range(1, max_n):
    if(amari==1):
      print(k)
      sys.exit()
    n_amari = (amari*10)%L
    amari = n_amari

Submission status: Wrong Answer

Solution code:
import sys

K = int(input())

max_n = 9000005
ans = 0
if(K%2==0) and (K%5==0):
  print(-1)
  sys.exit()
elif(K%7==0):
  L = 9*K/7
  amari = 10%L
  for k in range(1, max_n):
    if(amari==1):
      print(k)
      sys.exit()
    n_amari = (amari*10)%L
    amari = n_amari
else:
  L = 9*K
  amari = 10%L
  for k in range(1, max_n):
    if(amari==1):
      print(k)
      sys.exit()
    n_amari = (amari*10)%L
    amari = n_amari

Submission status: Wrong Answer

Solution code:
import sys

K = int(input())

max_n = 1000005
ans = 0
if(K%2==0) and (K%5==0):
  print(-1)
  sys.exit()
elif(K%7==0):
  L = 9*K/7
  amari = 10%L
  for k in range(1, max_n):
    if(amari==1):
      print(k)
      sys.exit()
    n_amari = (amari*10)%L
    amari = n_amari
else:
  L = 9*K
  amari = 10%L
  for k in range(1, max_n):
    if(amari==1):
      print(k)
      sys.exit()
    n_amari = (amari*10)%L
    amari = n_amari

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

k = int(input())

def prime_factorize(n):
    a = defaultdict(int)
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1
    return a

def f(k):
  if k % 2 == 0 or k % 5 == 0:
    return -1    

  val = 7
  cnt = 1
  while True:
    if val % k == 0:
      break
    cnt += 1
    val = val * 10 + 7
  return cnt
    
li = prime_factorize(k)

ans = 1
for k, v in li.items():
  if k ** v <= 10000:
    ans *= f(k) * k ** (v - 1)
  else:
    ans *= (k - 1) * k ** (v - 1)
    
if ans < 0:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

k = int(input())

def prime_factorize(n):
    a = defaultdict(int)
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1
    return a

def f(k):
  if k % 2 == 0 or k % 5 == 0:
    return -1    

  val = 7
  cnt = 1
  while True:
    if val % k == 0:
      break
    cnt += 1
    val = val * 10 + 7
  return cnt
    
li = prime_factorize(k)

li = {343:1}

ans = 1
for k, v in li.items():
  if k ** v <= 10000:
    ans *= f(k) * k ** (v - 1)
  else:
    ans *= (k - 1) * k ** (v - 1)
    
if ans < 0:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

k = int(input())

def prime_factorize(n):
    a = defaultdict(int)
    while n % 2 == 0:
        a[2] += 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] += 1
    return a

def f(k):
  if k % 2 == 0 or k % 5 == 0:
    return -1    

  val = 7
  cnt = 1
  while True:
    if val % k == 0:
      break
    cnt += 1
    val = val * 10 + 7
  return cnt
    
li = prime_factorize(k)

ans = 1
for k, v in li.items():
  if k <= 10000:
    ans *= f(k) ** v
  else:
    ans *= (k - 1) ** v
    
if ans < 0:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())
ans = 7%K
A = 1
C = [0]*K
if K == 1 or K == 7:
  print(1)
  exit()
for i in range(K):
  A = (A*10)%K
  ans += (A*7)
  ans %= K
  if ans == 0:
    break
  if C[ans] == 0:
    C[ans] += 1
  else:
    break
if i == K:
  print(-1)
else:
  print(i+2)

Submission status: Wrong Answer

Solution code:
import io
import sys

_INPUT = """\
999983
"""
sys.stdin = io.StringIO(_INPUT)

K = int(input())

x = 7 % K
s = set()
count = 0
while(True):
    count += 1
    if x in s:
        print(-1)
        break
    else:
        s.add(x)
        if x == 0:
            print(count)
            break
        x = (10*x+7) % K

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k = int(input())

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

def f(k):
  if k % 2 == 0 or k % 5 == 0:
    return -1    

  val = 7
  cnt = 1
  while True:
    if val % k == 0:
      break
    cnt += 1
    val = val * 10 + 7
  return cnt
    
li = prime_factorize(k)

ans = 1
for l in li:
  if l <= 10000:
    ans *= f(l)
  else:
    ans *= (l - 1)
    
if ans < 0:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
k = int(input())

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

def f(k):
  if k % 2 == 0 or k % 5 == 0:
    return -1    

  val = 7
  cnt = 1
  while True:
    if val % k == 0:
      break
    cnt += 1
    val = val * 10 + 7
  return cnt
    
li = prime_factorize(k)

ans = 1
for l in li:
  if l <= 1000:
    ans *= f(l)
  else:
    ans *= (l - 1)
    
if ans < 0:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

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

if(K % 2 == 0 or K % 5 == 0):
    print(-1)
if(K == 7):
    print(1)
else:
    for i in range(1,10**6):
        seven = (seven * 10 + 7) % K
        if(seven % K == 0):
            print(i+1)
            break

        # これだと10^5以降の計算が遅くなる。countのせい？？
        # count += 1
        # seven = seven + 7 * (10 ** count)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n==0:
    print(0)
if n%2==0:
    print(-1)
elif n%5==0:
    print(-1)
else:
    k=7
    l=1
    while k!=0:
        l+=1
        k*=10
        k+=7
        k%=n
        #print(k)
    print(l)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 1
seven = 7

if n%2==0:
  print(-1)
  exit()
  
while cnt<n:
  if seven%n==0:
    print(cnt)
    exit()
  seven = (seven*10+7)%n
  cnt += 1
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 1
seven = 7
if n%2==0:
  print(-1)
  exit()
while cnt<n:
  if seven==0:
    print(cnt)
    exit()
  seven = (seven*10+7)%n
  cnt += 1
print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 1
seven = 7

while cnt<n:
  if seven==0:
    print(cnt)
    exit()
  seven = (seven*10+7)%n
  cnt += 1
print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())

memo = set()
repunit = 7
n = 1
while True:
    if repunit == 0:
        print(n)
        exit()
    else:
        if repunit in memo:
            print(-1)
            exit()
        else:
            memo.add(repunit)
    repunit = (repunit*10 + 7)%K
    n += 1

Submission status: Wrong Answer

Solution code:
K = int(input())
seven = 0
count = 0

if(K % 2 == 0 or K % 5 == 0):
    print(-1)
else:
    while(seven % K != 0):
        seven = (seven * 10 + 7) % K
        count += 1

        # これだと10^5以降の計算が遅くなる。countのせい？？
        # count += 1
        # seven = seven + 7 * (10 ** count)

if(count >= 1): 
    print(count)