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

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

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


K = int(input())

# 解法1
# 数列 s は、s[1] = 7, s[i+1] = s[i] * 10 + 7 の漸化式で与えられる
# 特性方程式 α = α * 10 + 7 を考えると、α = -7/9 より、
# s[i+1] + 7/9 = 10 * (s[i] + 7/9) となる
# つまり、s[i] + 7/9 = 10^(i-1) * (7 + 7/9)
# <=> s[i] = 10^(i-1) * 70/9 - 7/9
# <=> s[i] = 7/9 * (10^i - 1)
# よって、7/9 * (10^i - 1) % K == 0 となるような最小の正の整数 i を求めれば良いことになる

# 解法2
# s[i] = s[i-1] * 10 + 7 より、s[i] % K = (s[i-1] * 10 + 7) % K
# a[i] = s[i] % K とすると、# a[i] = a[i-1] % K だから、
# a[i] を順番に計算し、a[i] == 0 となる最初の i を出力しても OK

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    i = 1
    a_i = 0
    while True:
        a_i = (a_i * 10 + 7) % K
        if a_i == 0:
            print(i)
            break
        i += 1

Submission status: Accepted

Solution code:
K = int(input())

cur = 7
flg = False
for i in range(10 ** 6):
    mod = cur % K
    if mod == 0:
        ans = i + 1
        flg = True
        break
    else:
        cur = mod * 10 + 7

if flg:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
k= int(input())

seen = [0]*(k+1)
rem=0
for i in range(0,k+1):
    rem = (rem*10+7) % k
    # print(rem)
    if rem == 0:
        print(i + 1)
        break
    elif seen[rem] ==1:
        print('-1')
        break
    else:
        seen[rem] =1

Submission status: Accepted

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:
    i = 1
    num = 10
    while True:
        num = num % L
        if num == 1:
            break
        else:
            i += 1
            num *= 10

    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

tmpNum = 7
count = 1
keisuu = 10

tmp = tmpNum%K
aa = tmp
while tmp !=0 and count<=K:
    aa = (aa*10)%K
    tmp = (tmp+aa)%K
    count+=1

if count>K:
    count=-1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
ref = 0
ans = 0

for i in range(K):
    ref = (10*ref + 7) % K
    if ref == 0:
        ans = i + 1
        break
    elif i == K - 1:
        ans = -1
        break

print(ans)

Submission status: Accepted

Solution code:
K = int(input())
m = 0
for i in range(K):
    m = (m * 10 + 7) % K
    if m == 0:
        print(i+1)
        break
    elif i == K-1:
        print(-1)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def power(x, n, mod):
    ans = 1
    while n > 0:
        if n % 2 == 1:
            ans = ans * x % mod
        n //= 2
        x = x * x % mod
    return ans

def eular(n):
    ans = 1
    if n % 2 == 0:
        x = 1
        while n % 2 == 0:
            n //= 2
            x *= 2
        ans *= x - x // 2
    i = 3
    while i * i <= n:
        if n % i == 0:
            x = 1
            while n % i == 0:
                n //= i
                x *= i
            ans *= x - x // i
        i += 2
    if n != 1:
        ans *= n - 1
    return ans

k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
    quit()
elif k % 7 == 0:
    l = 9 * k // 7
else:
    l = 9 * k

phi_l = eular(l)
ans = phi_l
d, x = 10, 1
while x * x <= phi_l:
    if phi_l % x == 0:
        if d % l == 1:
            ans = x
            break
        else:
            y = phi_l // x
            if pow(10, y, l) == 1:
                ans = y
    d = d * 10 % l
    x += 1
print(ans)

Submission status: Accepted

Solution code:
K = int(input())

if K%2 == 0 or K%5 == 0:
    print(-1)
else:
    if K%7 == 0:
        L = 9*K//7
    else:
        L = 9*K
    i = 1
    A = 10
    while i < 9000000:
        re = A%L
        if re == 1:
            print(i)
            break
        else:
            A = re*10
            i += 1
    else:
        print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
k=int(input())
n=k
x=7
for i in range(n):
    if x%k==0:
        print(i+1)
        break
    x=(x%k)*10+7
else:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())
x = 7%k

flg = False
for i in range(1,k+1):
  x = x%k
  if x ==0:
    flg = True
    break
  else:
    x = x*10+7
  
print(i if flg else '-1')

Submission status: Accepted

Solution code:
k = int(input())
x = 7 % k
s = set()
i = 1

while (not x in s):
    if x == 0:
        print(i)
        exit()
    s.add(x)
    x = (x*10+7) % k
    i += 1
print(-1)

Submission status: Accepted

Solution code:
K = int(input())

sevens = 0
count = 0
repeat = True

if {K%10} & {0,2,4,5,6,8}:
    count = -1
    repeat = False

while repeat:
    sevens = sevens % K * 10 + 7
    count += 1
    if sevens % K == 0:
        repeat = False

print(count)

Submission status: Accepted

Solution code:
k = int(input())
has = [False] * k
ans = 1
num = 7 % k

while num != 0 and not has[num]:
    has[num] = True
    num = (num * 10 + 7) % k
    ans += 1
    
if num == 0:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	k = int(input())
	x = 0
	for i in range(10**6):
		x = (10 * x + 7) % k
		if x == 0:
			print(i+1)
			exit()
	print(-1)

Submission status: Accepted

Solution code:
k = int(input())
if k % 2 == 0:
	print(-1)
elif k % 5 == 0:
	print(-1)
elif k%7 == 0:
	l = 9*k//7
	form = 1
	for i in range(l):
		if form * 10 % l == 1:
			print(i+1)
			break
		else:
			form = form * 10 % l 
else:
	l = 9 * k
	form = 1
	for i in range(l):
		if form * 10 % l == 1:
			print(i+1)
			break
		else:
			form = form * 10 % l

Submission status: Accepted

Solution code:
K = int(input())

if K == 1:
    print(1)
elif K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    if K % 7 == 0:
        L = 9 * K // 7
    else:
        L = 9 * K
    
    b = 10 % L
    for i in range(1, 1000000):
        if b == 1:
            print(i)
            break
        else:
            b = (10 * b) % L

Submission status: Accepted

Solution code:
# coding: utf-8

k = int(input())
n = 7 % k

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

Submission status: Accepted

Solution code:
cnt = 1
mod = 7
k = int(input())
for i in range(k):
    if mod % k == 0:
        break
    cnt += 1
    mod = (mod * 10 + 7) % k

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

Submission status: Accepted

Solution code:
cnt = 1
mod = 7
k = int(input())
for i in range(k):
  if mod%k == 0:
    break
  cnt+=1
  mod = (mod*10 + 7)% k

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

Submission status: Accepted

Solution code:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    c = 7
    count = 1
    while True:
        if c % k == 0:
            print(count)
            break
        else:
            c = (10 * c + 7) % k
            count += 1

Submission status: Accepted

Solution code:
K = int(input())

if K % 2 == 0:
    print(-1)
elif K % 5 == 0:
    print(-1)
else:
    seven = 7
    ans = 1
    while ans < 1000000:
        amari = seven % K
        if amari == 0:
            print(ans)
            break
        else:
            ans += 1
            seven = amari * 10 + 7
    else:
        print(-1)

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	k = int(input())

	# mod K 問題

	s = set()
	x = 7 % k
	i = 1
	cnt = -1
	while x not in s:
		if x == 0:
			cnt = i
			break
		s.add(x)
		x = (10 * x + 7) % k
		i += 1

	print(cnt)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import numpy as np
#import collections
#import math

#f = open('./input_C.txt')
#f = open('./input_C2.txt')

#K=int(f.readline())

K = int(input())

if K%7 == 0:
    L = 9*(K//7)
else:
    L = 9*K

#def CalcAmariSub(n,L,amari):
#    p=10000
#    if n <= p:
#        amari = (amari*(10**p))%L
#        return 0, amari
#    else:
#        amari = (amari*(10**p))%L
#        return n-p, amari
#
#def CalcAmari(n,L):
#    amari = 1
#    while n !=0:
#        n,amari = CalcAmariSub(n,L,amari)
#    return amari

ans = -1
amari = 1
for n in range(1,2*10**8):
    amari = (10*amari)%L
    if amari == 1:
        ans = n
        break

print(ans)

Submission status: Accepted

Solution code:
k = int(input())
m = 0

for i in range(k):
    m = (m * 10 + 7) % k
    if m == 0:
        break
    elif i == k - 1:
        print(-1)
        exit()

print(i + 1)

Submission status: Accepted

Solution code:
'''
参考
https://qiita.com/c-yan/items/d1b19114d411755f25b5
https://qiita.com/easychoco/items/7f1f00d9221bd3ab0a6c
数列は以下で表すことができる
a[n+1] = a[n] * 10 + 7
a[n] % K == 0となれば、その時点でのnが解となる
'''
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

num = 0

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

print(-1)

Submission status: Accepted

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

def get_input() -> int:
    """
    標準入力を取得する.

    Returns:\n
        int: 標準入力
    """
    K = int(input())

    return K


def main(K: int) -> None:
    """
    メイン処理.

    Args:\n
        K (int): 整数（1 <= K <= 10^6）
    """
    # 求解処理
    ans = -1
    remainder = 7 % K
    for i in range(1, 9000000):
        if remainder == 0:
            ans = i
            break
        remainder = (10 * remainder + 7) % K

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    K = get_input()

    # メイン処理
    main(K)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力を取得
K = int(input())

# 求解処理
ans = -1
remainder = 7 % K
for i in range(1, 9000000):
    if remainder == 0:
        ans = i
        break
    remainder = (10 * remainder + 7) % K

# 結果出力
print(ans)

Submission status: Accepted

Solution code:
from sys import exit

# import copy
# import numpy as np
from collections import deque, Counter


(K,) = map(int, input().split())

q = Counter([])
tmp = K

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


if K % 7 == 0:
    L = 9 * K / 7
else:
    L = 9 * K

tmp = 10

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

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

K = int(input())

val = 7
for n in range(1000010):
    val %= K
    if val == 0:
        print(n + 1)
        sys.exit(0)
    val *= 10
    val += 7

print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())
if k%2==0 or k%5==0:
  print(-1)
else:
  t=7
  ans=1
  while True:
    if t%k==0:
      print(ans)
      break
    t=(t*10+7)%k
    ans=ans+1

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

K = int(input())

i = 7
s = set()
count = 1

while True:
    j = i % K
    if j == 0:
        print(count)
        sys.exit()

    if j in s:
        print(-1)
        sys.exit()

    s.add(j)
    i = j*10 + 7
    count += 1

Submission status: Accepted

Solution code:
k = int(input())

val = 7
cnt = 1

while cnt <= 10 ** 6:
  val %= k
  if val % k == 0:
    print(cnt)
    exit()
  cnt += 1
  val = val * 10 + 7

print(-1)

Submission status: Accepted

Solution code:
K = int(input())
remainder_set = set()
sequence = 7
i = 1
for i in range(K):
    remainder = sequence%K
    #print(sequence,remainder)
    if remainder == 0:
        print(i+1)
        break
    else:
        if remainder in remainder_set:
            print(-1)
            break
        else:
            i += 1
            remainder_set.add(remainder)
            sequence = remainder*10 + 7

Submission status: Accepted

Solution code:
K = int(input())
count = 1
mod = 7
answer = -1

for i in range(K):
    if mod % K == 0:
        answer = count
        break
    count += 1
    mod = (mod * 10 + 7) % K

print(answer)

Submission status: Accepted

Solution code:
K = int(input())
se = set()
x = 7 % K
cnt = 1
while True:
    if x == 0:
        print(cnt)
        exit()
    if x in se:
        print(-1)
        exit()
    se.add(x)
    x = (10 * x + 7) % K
    cnt += 1

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  k=I()
  st=7
  if k==1 or k==7:
    return 1
  for i in range(1,1000001):
    st+=7*pow(10,i,k)
    st%=k
    if st==0:
      return i+1

  return -1

# main()
print(main())

Submission status: Accepted

Solution code:
K = int(input())

if K % 7 == 0:
    L = 9 * K // 7
else:
    L = 9 * K

ans = 10
kou = -1
for i in range(1, 10**6):
    ans %= L
    if ans == 1:
        kou = i
        break
    else:
        ans *= 10

print(kou)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
k = int(input())
x = 0
for i in range(k+1):
    x *= 10
    x %= k
    x += 7
    x %= k
    if x == 0:
        print(i+1)
        break
else:
    print(-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
K = int(input())
count = 1
tmp = 7
while count < 10**6+1:
    tmp %= K
    if tmp == 0:
        print(count)
        exit()
    tmp = tmp*10 + 7

    count += 1

print(-1)

Submission status: Accepted

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)
    exit()

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

print(ans)

Submission status: Accepted

Solution code:
import sys

K = int(input())

count = 1
ans = -1
remainder = 0
check = [False] * (K + 1)

while True:
    remainder = (remainder * 10 + 7) % K
    if remainder == 0:
        ans = count
        break

    if check[remainder]:
        break

    check[remainder] = True
    count += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
mod=7
for i in range(n):
  if mod%n==0:
    print(i+1)
    exit()
  mod=(mod*10+7)  %n
print(-1)

Submission status: Accepted

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

import sys
input=sys.stdin.readline

def judge(k):
    if k%2==0 or k%5==0:
        print(-1)
    else:
        tmp=0
        for i in range(10**6):
            tmp+=7
            tmp%=k
            if tmp==0:
                print(i+1)
                break
            else:
                tmp*=10

k=int(input())
judge(k)

Submission status: Accepted

Solution code:
k = int(input())

cnt = 1
mod = 7

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

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

Submission status: Accepted

Solution code:
N = int(input())
if N%2==0 or N%5==0:
  print(-1)
  
else:
  j = 1 
  mod = 7%N
  flag=True
  while flag:
    if mod==0:
      print(j)
      break
    elif mod>0:
      n = mod*10+7
      mod = n%N
      j+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

ai =0
ans = 0
# i = 1
l = set()

if K %2 == 0:
    ans = -1
else:
    for i in range(K):
        ai = (ai * 10 + 7) % K
        if ai == 0:
            ans = i+1
            break
        else:
            if ai in l:
                ans = -1
                break
            else:
                l.add(ai)
print(ans)

Submission status: Accepted

Solution code:
s, k = '', int(input())
for i in range(k):
    s += '7'
    s = str(int(s)%k)
    if not int(s): print(i+1); break
else: print(-1)

Submission status: Accepted

Solution code:

k=int(input())


if k%2==0 or k%5==0:
  i=-1
else:
  l=9*k if k%7 else 9*k//7
  i,n=1,10
  while n%l!=1:
    n=n*10%l
    i+=1

print(i)

Submission status: Accepted

Solution code:
k = int(input())
if k % 2 and k % 5:
  i = 7
  for t in range(10000000):
    i %= k
    if i == 0:
      print(t+1)
      quit()
    i *= 10
    i += 7
else:
  print(-1)

Submission status: Accepted

Solution code:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    
else:
    if K % 7 == 0:
        L = 9 * K // 7
    else:
        L = 9 * K
    n = 1
    P = 10 % L
    while True:
        if P == 1:
            print(n)
            break
        n += 1
        P = (10 * P) % L

Submission status: Accepted

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

if flag==0:
    print(-1)

Submission status: Accepted

Solution code:
import sys

if sys.argv[-1] == "ONLINE_JUDGE":
    from numba.pycc import CC
    cc = CC("solve")

    @cc.export('solve', 'i8(i8)')
    def f(k):
        a = 7 % k
        for i in range(k):
            if a == 0:
                return i + 1
            a = (a * 10 + 7) % k
        else:
            return -1
    cc.compile()
    exit(0)

from solve import solve
print(solve(int(input())))

Submission status: Accepted

Solution code:
from numba import njit,prange
@njit('i8(i8)',cache=True)
def f(k):
    a = 7%k
    for i in prange(k):
        if a == 0:
            return i+1
        a = (a*10+7)%k
    else:
        return -1
k = int(input())
print(f(k))

Submission status: Accepted

Solution code:
from numba import njit
@njit(cache=True)
def f(k):
    a = 7%k
    for i in range(k):
        if a == 0:
            print(i+1)
            break
        a = (a*10+7)%k
    else:
        print(-1)
k = int(input())
f(k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
k=int(input())
if k%2==0 or k%5==0:
    print(-1)
    sys.exit()
else:
    if k%7==0:
        l=(k//7)*9
    else:
        l=9*k
        
    j = 1
    n = 10
    rem = n%l
    while True:
        if rem == 1:
            print(j)
            sys.exit()
        rem = (rem*10)%l
        j+=1

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    K = int(input())
    x = 0
    i = 0
    if K % 2 == 0 or K % 5 ==  0:
        print(-1)
        exit()
    
    while True:
        x = (x * 10 + 7) % K
        i += 1
        if x == 0:
            print(i)
            break


    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

# In[40]:


K = int(input())


# In[44]:


if K%2 == 0 or K%5 == 0:
    print(-1)
else:
    if K%7 == 0:
        L = 9*K//7
    else:
        L = 9*K
    ans = -1
    tmp = 0
    for i in range(1,K+1):
        if (10*tmp+9)%L == 0:
            ans = i
            break
        else:
            tmp = (10*tmp+9)%L
    print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
k = int(input())
ans = 0
mod = 7
flag = 0
for i in range(10 ** 6 + 1):
    ans += 1
    if mod % k == 0:
        flag = 1
        break
    else:
        mod = (mod % k) * 10 + 7

if flag == 1:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
k=int(input())

if k%7==0:
    l=9*k//7
else:
    l=9*k

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

Submission status: Accepted

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

if K%7==0:
    L=9*K//7
else:
    L=9*K

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

Submission status: Accepted

Solution code:
k=int(input())
if k==7:
    print(1)
    exit()
if k%7==0:
    k//=7

x=9
for i in range(1,9000000):
    if x%(9*k)==0:
        print(i)
        exit()
    x%=(9*k)
    x*=10
    x+=9
print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

else:
    if k % 7 == 0:
        L = k * 9 // 7
    
    else:
        L = k * 9
        
    amari = 10 % L
        
    for i in range(1,10**6+1):
        if amari == 1:
            ans = i
            break
        
        amari = (amari * 10) % L
        
print(ans)

Submission status: Accepted

Solution code:
k = int(input())
x = 7 % k
ans = 1
for i in range(k):
    if x == 0:
        print(ans)
        exit()
    ans += 1
    x = (x * 10 + 7) % k

print(-1)

Submission status: Accepted

Solution code:
K = int(input())
now = 7

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

print(-1)

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

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

Submission status: Accepted

Solution code:
k=int(input())
s={7%k}
a=7%k
n=1
flag=True
while not {0}<=s:
    a=(a*10+7)%k
    beforelen=len(s)
    s.add(a)
    if len(s)==beforelen:
        flag=False
        break
    n+=1
print(n if flag else -1)

Submission status: Accepted

Solution code:
k = int(input())
i = 0
t = 1
k = k*9

if k%7 == 0 :
    k = k/7
if k%2 == 0 or k%5 == 0:
    i = -1
else:
    while(True):
        t *= 10
        i += 1
        t = t%k
        if t==1:
            break
    
print(i)

Submission status: Accepted

Solution code:
K = int(input())
N = 10
a = 0
l = 9*K
if(K==7 or K==1):
  a+=1
  print(1)
else:
  for i in range(1,10**6):
    N = (10*N)%l
    if (N*7-7)%l==0:
      print(i+1)
      a +=1
      break
  if(a == 0):
    print(-1)

Submission status: Accepted

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

rl = sys.stdin.buffer.readline
INF = sys.maxsize


K = int(rl())

def solve(K):
  L = ((9 * K) // 7) if K % 7 == 0 else (9 * K)
  if L % 2 == 0 or L % 5 == 0:
    return -1
  a = 1 % L
  for i in range(L):
    a = (a * 10) % L
    if a == 1:
      return i + 1

  return -1

print(solve(K))

Submission status: Accepted

Solution code:
k = int(input())

mod = 7

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

if mod % k == 0:
    ans = i + 1
else:
    ans = -1

print(ans)

Submission status: Accepted

Solution code:
k=int(input())
flag=True
seq=7
"""
これは階乗を含むのでO(klogk)で重い
for i in range(1,k+1):
  if (7*(10**i-1)//9) % k==0:
    print(i)
    flag=False
    break
"""
for i in range(1,k+1):
  if seq%k==0:
    print(i)
    flag=False
    break
  seq=(seq*10+7)%k  # %k(modの考え方)がなければ10**6ではO(k)は重すぎた
  
if flag:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
ans = -1
x = 7 % k
if not k%2 == 0:
    for i in range(1, k+1):
        if x == 0:
            ans = i
            break
        x = (x * 10 + 7) % k


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
remain = 0
i = 0

answer = -1

for i in range(1, K+5):
    number = remain*10 + 7

    remain = number % K

    if remain == 0:
        answer = i
        break

print(answer)

Submission status: Accepted

Solution code:
K = int(input())

n = 1
x = 7


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

while 1:
  if x % K == 0:
    print( n )
    break
  x = (x * 10 + 7) % K
  n += 1
#

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    lim = 2000000
    s = 0
    for i in range(lim):
        s *= 10
        s += 7
        s %= n
        if s == 0:
            print(i + 1)
            exit()
    print(-1)

solve()

Submission status: Accepted

Solution code:
k = int(input())
target = 7; ans = -1
if not k % 2== 0:
    
    for i in range(1, k + 10):
        if target % k == 0:
            ans = i
            break
        target = (target * 10 + 7) % k
 
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
if N % 7:
    L = 9*N
else:
    L = 9*N//7
num = 1
if L % 2 and L % 5:
    i = 1
    while i <= L:
        num = (num*10) % L
        if num == 1:
            print(i)
            break

        else:

            i += 1

else:
    print(-1)

Submission status: Accepted

Solution code:

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

    print(-1)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
K = int(input())
i = 1
ret = -1
if K % 5 != 0 and K % 2 != 0:
  N = 10
  if K % 7 == 0:
    L = K * 9 // 7
  else:
    L = K * 9
  while True:
    if N % L == 1:
      ret = i
      break
    N = (N * 10 )% L
    i += 1
print(ret)

Submission status: Accepted

Solution code:
k = int(input())
tmp = 7
ans = 1
while tmp % k != 0:
    tmp = (tmp % k) * 10 + 7
    ans += 1
    if ans > k:
        ans = -1
        break
print(ans)

Submission status: Accepted

Solution code:
k = int(input())
if k % 7 == 0: k = k // 7
tmp = 1
ans = 1
while tmp % k != 0:
    tmp = (tmp % k) * 10 + 1
    ans += 1
    if ans > k:
        ans = -1
        break
print(ans)

Submission status: Accepted

Solution code:
k = int(input())
x = 1

if k%7 != 0:
    mod = 9*k
else:
    mod = 9*k//7

for i in range(10**6):
    x = x*10%mod
    if x == 1:
        print(i + 1)
        exit()

print(-1)

Submission status: Accepted

Solution code:
#C_Repsept
K = int(input())
if K % 7 == 0 :
    L = int( 9 * K / 7 )
else:
    L = 9 * K
X = 0
kekka = 1
total = -1
if L % 2 == 1:
    if L % 5 != 0:
        for i in range(L): 
            kekka = kekka * 10 % L
            if kekka == 1:
                total = i+1
                break
# 出力
print(total)

Submission status: Accepted

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

for i in range(1,K+1):
    if num % K == 0:
        ans = i
        break
    num = (num * 10 + 7) % K
#ex.余りの数列を見ると、mod9のとき、7,5,3,1,8...と続く
#この時、(前項*10+7)のmod9を求めていることが分かる。
#1桁上がった値の余りと,同じ値を数列に入れることができるのでこれをループして値の発散を防ぐ。
#ex.77≡5 (mod9) 777≡3 (mod9) 7777≡1 (mod9)
print(ans)

Submission status: Accepted

Solution code:
K = int(input())
s = set()
x = 7%K
ans = 1

for i in range(K):
  if x == 0:
    break
  s.add(x)
  x=(x*10+7)%K
  ans+=1
  if x in s:
    ans=-1
    break

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

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

ans = 0
ai = 0
while True:
    ai = (ai * 10 + 7) % K
    ans += 1
    if ai % K == 0:
        print(ans)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

k = int(input())
n = 0 

cnt = 0 
for i in range(k):
    n = (10*n + 7)%k
    if n==0:
        print(i+1)
        exit()

print(-1)