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

ipt = input()
ipt = int(ipt)

res = 1
ok = False
while res < 1000000:
    if num % ipt==0:
        print(res)
        ok = True
        break
    else:
        num = num % ipt
        res = res + 1
        num = num*10 +7

if ok == False:
    print(-1)

Submission status: Accepted

Solution code:
# abc173a
def main():
    import sys

    input = sys.stdin.readline

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

Submission status: Accepted

Solution code:
K = int(input())

S = set()
ans = 1
x = 7 % K
while True:
    if x in S:
        ans = -1
        break
    if x == 0:
        break
    ans += 1
    S.add(x)
    x = ((10 * x) % K + 7 % K ) % K

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

if K%7 == 0:
  L = 9*K/7
else:
  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: Accepted

Solution code:
K=int(input())
result=-1
if K%2!=0 and K%5!=0:
  a=0
  b=7
  for i in range(K):
    a+=b
    a=a%K
    b=(b*10)%K
    if a==0:
      result=i+1
      break
      
print(result)

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:
# AFTER CONTEST


def solve(n):
    if n % 7 == 0:
        n //= 7

    if n % 2 == 0 or n % 5 == 0:
        return -1

    # Since R(k) = 1...1 = (10^k - 1) / 9, we have
    #   n | R(k)
    #   <=> 10^k = 1 ∈ Z_9n
    n9 = n * 9
    d = 10 % n9
    for i in range(n9):
        if d == 1:
            return i + 1
        d = (10 * d) % n9
    raise RuntimeError()


def main(istr, ostr):
    (k,) = list(map(int, istr.readline().strip().split()))
    result = solve(k)
    print(result, file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)

Submission status: Accepted

Solution code:

def solve():
	n=int(input())
	if n%2==0 or n%5==0:
		print(-1)
		return 
	ans=1
	p=7%n
	while(p!=0):
		p=(p*10+7)%n
		ans+=1
	print(ans)
if __name__ == "__main__":
	#code goes below
	# for _ in range(int(input())):
	solve()

Submission status: Accepted

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

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

print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
k=int(input())
num=7%k
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: Accepted

Solution code:
k=int(input())
num=7%k
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: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math

def input(): return sys.stdin.readline().rstrip("\r\n")
def List(): return list(map(int, input().split()))
def Num(): return int(input())


n = Num()
seven = 7
for I in range(n):
    if seven % n == 0:
        print(I + 1)
        break
    seven = seven * 10 + 7
    seven %= n
else:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())

flag = False

resid  = 7
if resid%k==0:
    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: Accepted

Solution code:
k=int(input())
def exit():
    import sys
    sys.exit()
if k%10 in [0,2,4,5,6,8,]:
    print(-1)
    exit()
i=1
if k%7==0:
    a=10%(9*k/7)
else:
    a=10%(9*k)
while 1:
    if k%7==0:
        if a==1:
            print(i)
            exit()
        a=(a*10)%(9*k/7)
    else:
        if a==1:
            print(i)
            exit()
        a=(a*10)%(9*k)
    i+=1

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    np.set_printoptions(threshold=20)
    K = int(input())
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return
    cnt = 0
    now = 7
    while True:
        cnt += 1
        if now % K == 0:
            print(cnt)
            return
        now = now * 10 + 7
        now %= K


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def Ra():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
sys.setrecursionlimit(10**9)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()

########################################################################################################################################################################


def dijkstra(edge,st):
    # edge=[[(v_to,dist_to_v),...],[],...]
    # initialize: def: d=dist(st,i), prev=[previous vertex in minimum path], q[]
    n=len(edge)
    d=[(0 if st==i else inf) for i in range(n)]
    q=[(j,i) for i,j in enumerate(d)]
    heapify(q)
    v=[False]*n
    # calc
    while q:
        dist,cur=heappop(q)
        if v[cur]:
            continue
        v[cur]=True
        for dst,dist in edge[cur]:
            alt=d[cur]+c[cur]
            if alt<d[dst]:
                d[dst]=alt
                heappush(q,(alt,dst))
    return d

class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
 
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self._root(self.table[x])
            return self.table[x]
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
    
    def __str__(self):
        rt=[i if j<0 else j for i,j in enumerate(self.table)]
        return str(rt)

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo



show_flg=False
show_flg=True

ans=0


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

print(-1)

Submission status: Accepted

Solution code:
k = int(input())
c = 0
x = 7
found = False
while c <= k:
    if x % k == 0:
        found = True
        break
    c += 1
    x = ((x * 10) + 7) % k

if not found:
    print(-1)
else:
    print(c + 1)

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


K = II()

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
k = int(input())

ans = 1
mod = 7

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

print(-1)

Submission status: Accepted

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

    x = 7 % K
    s = set()
    i = 1

    while True:
        # 割り切れる
        if x == 0:
            print(i)
            return

        # 割り切れない、無限ループ
        if x in s:
            print(-1)
            return

        s.add(x)
        x = (x * 10 + 7) % K
        i += 1


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

i = 1
mod = 10**i % L
while True:
    if mod == 1:
        print(i)
        sys.exit()

    mod = mod * 10 % L
    i += 1

Submission status: Accepted

Solution code:
K=int(input())

a=7%K
i=1
dp=[0 for n in range(K)]
dp[a]=1

while a!=0:
   a=(10*a+7%K)%K
   if dp[a]==0:
       dp[a]+=1
       i+=1
   else:
       print(-1)
       break
else:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


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

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

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

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(K):
    visited = [False] * K
    p = 7 % K
    for i in range(K):
        if p == 0:
            return i + 1
        if visited[p]:
            return - 1
        visited[p] = True
        p = (p * 10 + 7) % K


def solve(K):
    p = 7 % K
    for i in range(K):
        if p == 0:
            return i + 1
        p = (p * 10 + 7) % K
    return - 1


def main():
    # parse input
    K = int(input())
    print(solve(K))


# tests
T1 = """
101
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
4
"""
T2 = """
2
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
-1
"""
T3 = """
999983
"""
TEST_T3 = """
>>> as_input(T3)
>>> main()
999982
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()

Submission status: Accepted

Solution code:
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
# stdin = open("sample.txt")


MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def main():
    K = int(stdin.readline().rstrip())
    L = 0
    amari = 10
    if K % 2 == 0 or K % 5 == 0:
        print("-1")
    else:
        if K % 7 == 0:
            L = 9*K//7
        else:
            L = 9*K
        for i in range(1,1000000):
            if amari % L == 1:
                print(i)
                break
            else:
                amari = (amari % L) * 10
main()

Submission status: Accepted

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

    L = 9 * K // 7 if K % 7 == 0 else 9 * K
    if L % 2 == 0 or L % 5 == 0:
        return -1

    remainder = 1
    for n in range(1, L + 1):
        remainder = (10 * remainder) % L
        if remainder == 1:
            return n
    return -1

print(c_repsept())

Submission status: Accepted

Solution code:
k = int(input())
tens = 10
exist = False
count = 1

if k % 2 == 0:
  exist = False
elif k % 5 == 0:
  exist = False
else:
  if k % 7 == 0:
    L = 9 * k / 7
  else:
    L = 9 * k
  for i in range(9000000):
    if tens % L == 1:
      exist = True
      break
    tens = tens % L * 10 % L
    count += 1
    

if exist:
  print(count)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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+10):
        a = (a * 10) % L
        if a == 1:
            print(i)
            return
    print(-1)
main()

Submission status: Accepted

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

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

if K % 2 == 0 or K % 5 == 0:
    res = -1
else:
    if K % 7 == 0:
        K /= 7
    while True:
        res += 1
        surplus = (10 * surplus) % (9*K)
        if surplus == 1:
            break
print(res)

Submission status: Accepted

Solution code:
K = int(input())

N = 1000000
x = 7 % K

for i in range(1, N+1):
    if x == 0:
        break
    x = (x * 10 + 7) % K

if i == N:
    i = -1

print(i)

Submission status: Accepted

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


# def solve(K: int) -> int:
def solve(K):
    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: Accepted

Solution code:
K=int(input())

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
k =int(input())

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

Submission status: Accepted

Solution code:
import sys

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())

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

Submission status: Accepted

Solution code:
import sys

def main():
    K = int(sys.stdin.readline())
    
    if K%2==0:
        print(-1)
        return
    
    if K % 7:
        L = 9*K
    else:
        L = 9*K//7
    a = 1
    for i in range(1,L+1):
        a = (a * 10) % L
        if a == 1:
            print(i)
            return
    print(-1)
main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
res = f_inf


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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc174/abc174_c
import sys
 
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
 
def main():
    K = i2n()
    a = 0
    if K % 7:
        L = 9 * K
    else:
        L = 9 * K // 7
    a = 1
    for i in range(1, K + 10):
        a = (a * 10) % L
        if a == 1:
            print(i)
            return
    print('-1')
    return

main()

Submission status: Accepted

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


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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
k = int(input())
mod = 7 % k
cnt = 1
answer = -1

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

Submission status: Accepted

Solution code:
K = int(input())

ans = -1
history = set()
b = 0

for i in range(K):
    b = (10 * b + 7) % K

    # loop
    if b in history:
        break

    # success
    if b == 0:
        ans = i + 1
        break

    history.add(b)

print(ans)

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:
def main():
    k = int(input())
    ans = 1
    n = 7%k
    a = [-1 for i in range(k)]
    while True:
        if n==0:
            print(ans)
            return
        if a[n]==-1:
            a[n] = 1
            ans += 1
            n = (n*10+7)%k
        else:
            print(-1)
            return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
K = input()
K_1 = int(K[-1])
K = int(K) 

mod_ini = 7%K
mod = 0
cnt = 0

while True:
    if K%2 == 0 or K_1 == 5:
        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: Accepted

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

Submission status: Accepted

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


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

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

    rest = [7 % k]

    for i in range(k):
        rest.append(rest[-1] * 10 % k)

    tmp = 0
    for i in range(k):
        if (tmp + rest[i]) % k == 0:
            print(i + 1)
            return
        else:
            tmp = (tmp + rest[i]) % k
    else:
        print(-1)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
k=int(input())
if k%2==0 or k%5==0:
  print(-1)
  sys.exit()
s=7
for i in range(k):
  m=s%k
  if m==0:
    print(i+1)
    break
  s=m*10+7

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

cnt = 1

if(K%2 == 0):
    print(-1)
elif(K%5 == 0):
    print(-1)
else:
    n = 0
    a = 0
    while(1):
        n = a*10+7
        a = n%K
        if(a==0):
            print(cnt)
            break
        cnt += 1

Submission status: Accepted

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

K = int(readline())

cur = 0
mods = set()
cnt = 0
while True:
  cnt += 1
  
  cur *= 10
  cur += 7
  cur %= K
  if cur == 0:
    print(cnt)
    break
  if cur in mods:
    print(-1)
    break
  mods.add(cur)

Submission status: Accepted

Solution code:
k = int(input())

x = 7 % k

s = [0] * k
i = 1

while s[x] == 0:
    if x == 0:
        print(i)
        exit()
    s[x] = 1
    x = (x * 10 + 7) % k
    i += 1

print('-1')

Submission status: Accepted

Solution code:
k=int(input())
x=7
cnt=1
if k%2==0:
    print(-1)
else:
    while True:
        if x%k ==0:
            print(cnt)
            break
        elif cnt<10000000:
            x=(x*10+7)%k
            cnt+=1
        else:
            print(-1)
            break

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
K = int(input())
t = 7
t %= K

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

Submission status: Accepted

Solution code:
import sys
K = int(input())
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)