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

flg = [False]*K

tmp = 7 % K
cnt = 1
if tmp == 0:
    print(cnt)
    exit()
while True:
    tmp = (tmp*10+7)%K
    if flg[tmp]:
        print(-1)
        break
    else:
        cnt += 1
        if tmp == 0:
            print(cnt)
            break
        flg[tmp] = True

Submission status: Accepted

Solution code:
import sys
K = input()
if K[-1] == '2' or K[-1] == '4' or K[-1] == '5' or K[-1] == '6' or K[-1] == '8' or K[-1] == '0':
    print(-1)
    sys.exit()
K = int(K)
n = 7 % K
i = 1
while i <= K:
    if n == 0:
        print(i)
        sys.exit()
    n = 10 * n + 7
    n %= K
    i += 1
print(-1)

Submission status: Accepted

Solution code:
K = int(input())

ans = 1
now = 7 % K
isvisited = set()

while now != 0:
    if now in isvisited:
        print(-1)
        exit()
    isvisited.add(now)
    now = (now * 10 + 7) % K
    ans += 1

print(ans)

Submission status: Accepted

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


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


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

Submission status: Accepted

Solution code:
import sys

K = int(input())

seven = 7
seven %= K
for i in range(K+2):
    if seven == 0:
        print(i+1)
        sys.exit()
    seven = seven * 10 + 7
    seven %= K

print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

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

print(res)

Submission status: Accepted

Solution code:
import sys

K = int(input())

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

print(-1)

Submission status: Accepted

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

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

print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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(k):
  m*=10
  m=m%k
  o+=m%k
  o%=k
  if o==0:
    print(i+1)
    exit()

Submission status: Accepted

Solution code:
k=int(input())
if k%2==0:
    print(-1)
    exit()
def solver(k):
    tmp=7%k
    cnt=1
    while cnt <= k:
        if tmp%k != 0:
            tmp=(tmp*10+7)%k
            cnt+=1
        else:
            return cnt
    return -1
        
print(solver(k))

Submission status: Accepted

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

Submission status: Accepted

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

Solution code:
k=int(input())
ans=7
ans2=10
prev=7
hbe=False
if ans%k==0:
    print(1)
    hbe=True
else:
    for i in range(0, k + 1, 1):
        ans=(7*ans2+prev)%k
        if ans%k==0:
            print(i+2)
            hbe=True
            break
        prev=ans
        ans2=(ans2*10)%k
if hbe==False:
    print(-1)

Submission status: Accepted

Solution code:
K = int(input())

#sevens = int('7' * len(str(K)))
sevens_mod = 7 % K
flag = False
ans = -1
for i in range(K):
    if sevens_mod == 0:
        flag = True
        ans = i + 1
        break
    sevens_mod = (sevens_mod * 10 + 7) % K
print(ans if flag else -1)

Submission status: Accepted

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
  if X == 1:
    print(1)
  else:
    for i in range(K):
      X = X*10 % L
      if X == 1:
        print(i+2)
        break

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

rem=1
for i in range(1,L+1):
    rem*=10
    rem=rem%L
    if rem==1:
        break
print(i)

Submission status: Accepted

Solution code:
k = int(input())

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

  val = 7
  cnt = 1
  while cnt < 10 ** 6:
    val %= k
    if val % k == 0:
      break
    cnt += 1
    val = val * 10 + 7
  else:
    return -1
  return cnt
    
print(f(k))

Submission status: Accepted

Solution code:
k = int(input())

f = 0
now = 0
a = [0] * k

for i in range(k):
    now = (now * 10 + 7) % k
    if(now == 0):
        print(i+1)
        f = 1
        break
    if(a[now] == 1): break
    a[now] = 1

if f == 0:
    print(-1)

Submission status: Accepted

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    k = int(input())
    x = 7%k
    y = set()
    cnt = 1
    for i in range(k+1):
        if x == 0:
            print(cnt)
            exit()
        if x in y:
            print(-1)
            exit()
        y.add(x)
        x = (x*10+7)%k
        cnt += 1




if __name__=="__main__":
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

k = 7
m = k%n
if m == 0:
    print(1)
    exit()
cnt = 1

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

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from fractions import Fraction
from itertools import combinations
from math import gcd
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    K = int(input())
    ss = set({})
    mod = 7 % K
    count = 1
    while True:
        if mod == 0:
            print(count)
            exit()
        if mod in ss:
            print(-1)
            exit()
        ss.add(mod)
        mod = (mod * 10 + 7) % K
        count += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())

x = 0

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

Submission status: Accepted

Solution code:
def f(k):
    r = 7%k
    i = 1
    s = set()
    while r not in s:
        if not r: return i
        i += 1
        s.add(r)
        r = (r*10 + 7)%k
    return -1

print(f(int(input())))

Submission status: Accepted

Solution code:
def f(k):
    r = 7%k
    s = set()
    for i in range(k):
        if not r: return i+1
        s.add(r)
        r = (r*10 + 7)%k
        if r in s: break
    return -1

print(f(int(input())))

Submission status: Accepted

Solution code:
import sys

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b

def solve():
    input = sys.stdin.readline
    K = int(input())
  
    N = 0
    for i in range(1, K + 1):
        N = (N * 10 + 7) % K
        if N == 0:
            print(i)
            break
    else:
        print(-1)
   
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def f(k):
    r = 7%k
    i = 1
    s = set()
    while r not in s:
        s.add(r)
        if not r: return i
        r = (r*10 + 7)%k
        i += 1
    return -1

print(f(int(input())))

Submission status: Accepted

Solution code:
K = int(input())

f=0
n=K

for i in range(10**6 + 1):
    if n == 0:
        f=1
        print(i)
        break
    n = ((n*10) + 7 ) % K
    
if f==0:
   print(-1)

Submission status: Accepted

Solution code:
x = int(input())
t = 7
amari = 0
flag = 0

for i in range(x):
    if t%x == 0:
        print(i+1)
        flag = 1
        break
    else:
        amari = t%x
        t = 7+(amari*10)


if flag == 0:
    print(-1)

Submission status: Accepted

Solution code:
def f(k):
    r = 7%k
    for i in range(k):
        if not r: return i+1
        r = (r*10 + 7)%k
    return -1

print(f(int(input())))

Submission status: Accepted

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

k = int(input())
ret = 1
res = 7%k
while res != 0 and ret <= k:
    res *= 10
    res += 7
    res %= k
    ret += 1
if res != 0:
    print(-1)
else:
    print(ret)

Submission status: Accepted

Solution code:
def f(k):
    r = 7%k
    for i in range(k):
        if r == 0: return i+1
        r = (r*10 + 7)%k
    return -1

print(f(int(input())))

Submission status: Accepted

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

Submission status: Accepted

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

    f=0
    n=num
    
    for i in range(10**6+1):
      if n==0:
        f=1
        print(i)
        break
      n=((n*10)+7)%num
    if f==0:
      print(-1)


if __name__ == '__main__':
    Repsept()

Submission status: Accepted

Solution code:
K = int(input())

cnt = set()
k = 7%K
i = 1

while k not in cnt:
  if k == 0:
    print(i)
    exit()

  cnt.add(k)
  k = (10*k+7) % K
  i += 1

print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

ans = -1
n = 10
for i in range(1, L):
    surplus = n % L
    if surplus == 1:
        ans = i
        break
    n = 10 * surplus
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys 
from collections import defaultdict
sys.setrecursionlimit(10**6)
MOD = 10**9+7 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
K = int(readline())
cnt = 0
N = 7
for i in range(K+1):
    if N % K == 0:
        print(i+1)
        sys.exit()
    N = (N*10+7) % K
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
    temp = 10 % L
    if temp == 1:
        print(1)
    else:
        for i in range(L):
            temp = (temp*10) % L
            if temp == 1:
                print(i+2)
                break

Submission status: Accepted

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(K):
    m = 0
    for i in range(1, 10**6):
        m = (m * 10 + 7) % K
        if m == 0:
            print(i)
            return
    print(-1)

if __name__ == '__main__':
    input = sys.stdin.readline
    K = int(input())
    main(K)

Submission status: Accepted

Solution code:
K = int(input())

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

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

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

  a=((10*a)+7)%k
    
print(ans)

Submission status: Accepted

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()
print(-1)

Submission status: Accepted

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 7*(tmp*10-1)%k:
        tmp*=10
        tmp%=k
        cnt+=1
    print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

i = 1
r = 7 % K
R = {r}
while r != 0:
    i += 1
    r = (r * 10 + 7) % K
    if r in R:
        print(-1)
        exit()
    R.add(r)

print(i)

Submission status: Accepted

Solution code:
k=int(input())
num=1
L=0
ans=-1


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

# if L%2==0 or L%5==0:
# 	ans=-1

for i in range(k+1):
	if (num*10)%L==1:
		ans=i+1
		break
	num=num*10 %L
print(ans)

Submission status: Accepted

Solution code:
K = int(input())

a = 7

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

Submission status: Accepted

Solution code:
K = int(input())
A = 7%K
Flag = False
for T in range(1,K+1):
    if A==0:
        Flag = True
        break
    else:
        A = (10*A+7)%K
print(['-1',T][Flag])

Submission status: Accepted

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 == 0:
    print(ans)
    exit()
  i += 1
print('-1')

Submission status: Accepted

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
print('-1')

Submission status: Accepted

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+10):
		# print(num)
		if num==0:
			ans=i
			break
		num=(num*10+7)%k

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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)
    if tmp == 7:
        print(i)
        exit()

print(-1)

Submission status: Accepted

Solution code:
"""
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
                                                                                                                                                            ..,,,,,,,,************,,,,,,,,,,,,,.        
                              ..,*.                                                                                                                           .,,,,,,,,,,,,,,,,,,,,,,,,...              
                       #&@@@@@@@@@@@@@@@@@(                                                                                                                     .....,,,,,,,.....                       
                   (*@@@@@@@@@@@@@@@@@@@@@@@@&*                                                                                                                                                 ...,,,,,
                &*&@@@@@@%@%,.*%@@@@@@@@@@@@@@@@&                                          (&@@@@&%/                                                                              ..,,,,,,,,,,,,,*******
              ##@@@@@@&#,             *@@@@@@@@@@@@                                 (@@@@@@@@@@@@@@@@@@@@@(                                .                                    /@@@@(,,,,,,,*********//
             (@@@@@@@.                   #@@@@@@@@@@*                           %@@@@@@@@@@@@&&@@@@@@@@@@@@@@@%                         ,@@@@@@%                             /@@@@@@(...,,,,,,,,,,,,,,**
           ,,@@@@@@,                        #@@@@@@@&,                       %@@@@@@@/                   #@@@@@@@&                      @@@@@@@@@&     ....                ,@@@@@@@/          ..,,,,,,,,
           ,@@@@@@,                           .&@@@@&.                     &@@@@@@.                         ,&@@@@@@,                    @@@@@@@@@@,                      @@@@@@@@%                ..,,,
          /&@@@@@/                               &@                      %@@@@@@                               #@@@@@@/                   /@@@@@@@@@@&                  @@@@@@@@@@                     .
           @@@@@@/                                                      &@@@@@,                                  *@@@@@@.                    @@@@@@@@@@@@            *@@@@@@@@@@&                       
           &&@@@@%                                                     @@@@@@            .&@@@@@@@@@@@@&           (@@@@@@                     #@@@@@@@@@@@#        @@@@@@@@@@@&                        
          *%&&@@@*#                                                   @@@@@@          /@@@@@@@@@@@@@@@@@@@%          @@@@@@                      .@@@@@@@@@@@@     @@@@@@@@@@@&                         
           .&@@@@@*(                                                 /@@@@@,         @@@@@@@@@@@# &@@@@@@@@@(         &@@@@@                       .@@@@@@@@@@@&  @@@@@@@@@@@,                          
            .&@@@@@@%                                                &@@@@@         @@@@@@@@@@@.     @@@@@@@@&         &@@@@@                         &@@@@@@@@@@@@@@@@@@@@                             
             (/@@@@@@@#.                                             @@@@@&        ,@@@@@@@@@          .@@@@@@%         @@@@@%                          @@@@@@@@@@@@@@@@@#                              
               &%@@@@@@@@@#                                          @@@@@&        *@@@@@@@@             /@@@@@&        ,@@@@@                            @@@@@@@@@@@@@@,                               
                 (,@@@/%@@@@@@@@@@@&,                                &@@@@@         @@@@@@@&              @@@@@@*        @@@@@.                             @@@@@@@@@@@                                 
                    . &@@@@@@@@@@@@@@@@@@@,                           @@@@@(        *@@@@@@@,            ,@@@@@@@        @@@@@,                            ,@@@@@@@@@@@@                                
                          .&@@@@@@@@@@@@@@@@@@,                       &@@@@@         (@@@@@@@&          ,@@@@@@@&        @@@@@                            @@@@@@@@@@@@@@@@                              
                                    (@@@@@@@@@@@@,                     &@@@@@          @@@@@@@@@@@@@&@@@@@@@@@@@        @@@@@@                          /@@@@@@@@.@@@@@@@@@&                            
                                         %@@@@@@@@@%                    @@@@@@           &@@@@@@@@@@@@@@@@@@@@(        #@@@@&                          (@@@@@@@&   .@@@@@@@@@/                          
                                            *@@@@@@@@#                   @@@@@@.            &@@@@@@@@@@@@@@,          &@@@@@.                         .@@@@@@@#       @@@@@@@@@                         
                                               &@@@@@@@                   &@@@@@&                                   %@@@@@@                          *@@@@@@@           @@@@@@@@&                       
                                                 &@@@@@@,                  %@@@@@@&                               &@@@@@@(                  .....,,.&@@@@@@&              #&@@@@@@.                     
                                                  %@@@@@@            ........@@@@@@@@ .                        %@@@@@@@(                 .,,,,,,,,*@@@@@@@                  /@@@@@@@                    
                                                   &@@@@@@        .....,,,,,,,,@@@@@@@@#                   *@@@@@@@@@.               ..,,,,,,,,,,%@@@@@@@                     .@@@@@@#                  
                                                    @@@@@@.    ....,,,,,,,,,,,@@@@@@@@@@@@@@#        *&@@@@@@@@@@@@@@@@          .,,,,,,,,,,,,,,@@@@@@@*                         @@@@@@,                
             *                                      @@@@@@,  ...,,,,,,,,,,,,(@@@@@@/@@@@@@@@@@@@@@@@@@@@@@@@@@&  @@@@@@@#    .,,,,,,,,,,,,,,,,#@@@@@@&                             @@@@@&               
            @@@@/                                   @@@@@@,...,,,,,,,,,,,,,@@@@@@@     *&@@@@@@@@@@@@@@@@%        @@@@@@@@,,,,,,&&#*,,,,,,,,,%@@@@@@                                 @@@@@#             
           &@@@@@                                  &@@@@@@,,,,,,&@@@@*,,,/@@@@@@&                                  *@@@@@@@*,,,*@@@&,,...   #@@@@@                                    .@@@@&            
           &@@@@@#                                @@@@@@@,,,,,,%@@@@@@@/@@@@@@@.                                   ..@@@@@@@(,,*@@@@(      (@@@@/                                       ,@@@@.          
           ,@@@@@@/                             &@@@@@@@,,,,,,,,,@@@@@@@@@@@@,                                  ....,,%@@@@@@%  @@@@@      @@@@                                           (@@@*         
            &@@@@@@@                         ,@@@@@@@@@,,,,,,,,,,,,/@@@@@@@@#                                 ..........@@@@@@% &@@@@     #@%                                               @@@&        
             #@@@@@@@@.                   (@@@@@@@@@@,,,,,,,,,,,.../@@@@@@@@@@@.                              ....       %@@@@@%.@@@@                                                        *@@#/      
              .@@@@@@@@@@&,          *@@@@@@@@@@@@&,,,,,,,,,...  .@@@@@@&*@@@@@@@%                                         @@@@@@@@@@&                                                         &@@(     
              @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%..,,,,,,....   .@@@@@@@.   #@@@@@@@                             &&&         %@@@@@@@@@                                                           %&%    
            &@@@@@@&@@@@@@@@@@@@@@@@@@@@@@@%............      @@@@@@@/        /@&%                             &@@@@@@@@&.    @@@@@@@@                                                             (&/  
           (@@@@@@,      *&@@@@@@@@@&/       ....           (@@@@@@#                                           &&@@@@@@@@@@@@@@@@@@@@@*                                                               * 
            ***                                            %@@@@@&                                                  .(@@@@@@@@@@@@@@@@%......                                                           
                                                             ,&,                                         ....,,,,,,,,,,,,,,,,,,/&@@@@@@*.                                                               
                                                                                                 ...,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...                                                                .,,,
                                                                                          ...,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,..                                                                 ..,,,,****
                                                                                     ..,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,..                                                                  .,,,,,,****////
"""
k = int(input())
x = 7 % k
for i in range(1, k + 10):
    if not x:
        print(i)
        exit()
    x = (10 * x + 7) % k
print(-1)

Submission status: Accepted

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

for n in range(1,K+10):
    if x==0:
        ans = n
        break

    x = (x * 10 + 7)%K
print(ans)

Submission status: Accepted

Solution code:
K=int(input())
 
j=0
ans=0
a=0
while True:
    a=a*10+7
    a=a%K
    ans+=1
    
    if a==0:
        break
    
    if ans>K:
        ans=-1
        break
 
print(ans)

Submission status: Accepted

Solution code:
k=int(input())

ch=7%k
flag=0
for i in range(1,10000001):
    if ch%k==0:
        print(i)
        flag=1
        break
    ch=(ch*10+7)%k
    
if not flag:
    print("-1")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
k = int(input())
num = 7%k
soln = False
for i in range(1, k+1):
    if num == 0: print(i); soln = 1; break
    num = ((((num%k) * (10%k))%k) + (7%k))%k
if not soln: print(-1)

Submission status: Accepted

Solution code:
k = int(input())

def func(k):
    number = 7 % k
    for i in range(k):
        if number == 0:
            return i+1
        number = (10 *number + 7) % k 
    return -1
    
if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    print(func(k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    k = i_input()

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

    tmp = 7
    count = 1        

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

    print(-1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())
x=i=0
while i<k:i+=1;x=(x*10+7)%k;x<1>exit(print(i))
print(-1)

Submission status: Accepted

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