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:
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------- fast io --------------------
from math import gcd, ceil

def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi


def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans

def lcm(a, b): return a * b // gcd(a, b)


def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y


for _ in range(int(input()) if not True else 1):
    #n = int(input())
    k = int(input())
    if k == 7:
        print(1)
        continue
    if k % 7 == 0:
        k = k // 7
    cur = 0
    start = 0
    found = False
    for i in range(8*10**6):
        start = (10*start + 1) % k
        if start == 0:
            found = i+1
            break
    print(-1 if not found else found)

Submission status: Accepted

Solution code:
K=int(input())

X=[0]*K
m=0
p=7
for i in range(K):
  m=(m+p)%K
  if m==0:
    print(i+1)
    break
  elif X[m]==1:
    print(-1)
    break
  else:
    X[m]=1
  p=(p*10)%K

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
k = int(input())

r = 0
c = 0
for i in range(1, 1000001):
    r *= 10
    r += 7
    c += 1

    r %= k
    if r == 0:
        break

if r != 0:
    print(-1)
else:
    print(c)

Submission status: Accepted

Solution code:
k=int(input())

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

Submission status: Accepted

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

print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

    if mod==0:
        break
print(ans if ans!=1000000 else -1)

Submission status: Accepted

Solution code:
import sys


def _i(): return int(sys.stdin.readline().strip())


def main():
    n = _i()
    last = 7 % n
    if last == 0:
        return 1

    m = {last: True}
    cnt = 1
    while True:
        nxt = (10 * last + 7) % n
        cnt += 1

        if nxt == 0:
            return cnt

        if m.get(nxt, False):
            return -1

        m[nxt] = True
        last = nxt


if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())
    
    if K == 1:
        print(1)
        return
    elif K % 2 == 0:
        print(-1)
        return
        
    n = 7 % K
    seen = [False] * K
    for i in range(1, 10 ** 8):
        if n == 0:
            print(i)
            return
        elif seen[n]:
            print(-1)
            return
        else:
            seen[n] = True
            n = (n * 10 + 7) % K
            
    
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

num,cnt="7",1
for i in range(1,n+1):
    if int(num)%n==0:
        print(i)
        exit()
    else:
        num +="7"
        num=str(int(num)%n)
print(-1)

Submission status: Accepted

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

K=int(input().rstrip('\n'))
if K % 2 ==0:
  print(-1)
else:
  now = 7
  check = 0
  for i in range(1,K+1):
    if now % K ==0:
      print(i)
      check += 1
      break
    else:
      now = now%K
      now = now*10
      now += 7 
  if check ==0:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())
d=[0 for i in range(k)]
t=7%k
i=1
while True:
  if t==0:
    break
  if d[t]:
    i=-1
    break
  d[t]=1
  t=(t*10+7)%k
  i+=1
print(i)

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

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

print(-1)

Submission status: Accepted

Solution code:
k = int(input())
a = [0] * k

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

Submission status: Accepted

Solution code:
k = int(input())

checked = [False for _ in range(k)]
r = 0
ans = -1

for i in range(1, k + 1):
    r = (r * 10 + 7) % k
    if checked[r]:
        break
    elif r == 0:
        ans = i
        break
    else:
        checked[r] = True

print(ans)

Submission status: Accepted

Solution code:
from itertools import count

K = int(input())
f = lambda x: (x*10+7)%K

a = 7%K
b = 7%K


for t in count(1):
    if a == 0:
        print(t)
        break
    if t > 1 and a == b:
        print(-1)
        break
    a = f(a)
    b = f(f(b))

Submission status: Accepted

Solution code:
K=int(input())
n=len(str(K))
N=int("7"*n)
if K%2==0 or K%5==0:
    print(-1)
else:
    while N%K!=0:
        n+=1
        N=N*10+7
        N%=K
    print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
X = 1
temp = 7
ans = 1

if K == 7 or K == 1:
  print(ans)
  exit()

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

Submission status: Accepted

Solution code:
K=int(input())
t='7'
while int(t)<int(K):
  t+='7'
  
c=len(t)
t=int(t)
nums=[1]*K
while int(t)>0:
  t%=K
  if t==0:
    print(c)
    exit()
    
  if nums[t]==1:
    nums[t]=0
    t=10*t+7
    c+=1
  else:
    print(-1)
    exit()

Submission status: Accepted

Solution code:
K = int(input())
ans = 1
count = 1
m = 10
if K%7 == 0:
  K //= 7
for j in range(K):
  if count % K == 0:
    print(ans)
    exit()
  else:
    count = (count + m)%K
    m = m*10%K
    ans += 1
print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K=int(input())

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

Submission status: Accepted

Solution code:
k = int(input())

dp = [0] * k

cur = 0
for i in range(k + 1):
    cur = (cur * 10 + 7) % k
    mod = cur % k
    if mod == 0:
        print(i + 1)
        break
    if dp[mod]:
        print(-1)
        break
    dp[mod] = 1

Submission status: Accepted

Solution code:
k=int(input())
i=1
a=7%k
m=10
v=set()
while True:
    v.add(a)
    if a==0:
        print(i)
        exit()
    a += m*7 %k
    a %= k
    if a in v:
        print(-1)
        exit()
    i+=1
    m *= 10
    m %= k

Submission status: Accepted

Solution code:
k=int(input())
if k%2==0:
    print (-1)
else:
    from collections import Counter
    c=Counter([])
    ans=1
    n=7%k
    flag=1
    while 1:
        if n==0:
            break
        if c[n]>=1:
            ans=-1
            break
        else:
            c[n]+=1
            n=(n*10+7)%k
            ans+=1
    print (ans)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

    v = 7
    for i in range(1, 1000000):
        if v % K == 0:
            print(i)
            return

        v = (v * 10 + 7) % K
        
    print(-1)

main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

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


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(K):
    c = 0
    for i in range(1, 10**6+1):
        c *= 10
        c += 7
        c %= K
        if c == 0:
            return i
    return -1


def main():
    K = read_int()
    print(slv(K))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

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

Submission status: Accepted

Solution code:
(K, ) = [int(n) for n in input().split()]

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

res = 7 % K
ans = 1
while res != 0:
    res *= 10
    res += 7
    res %= K
    ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
k = int(input())

count = 1
flag = 0
current = 7
for i in range(2000000):
	if current%k == 0:
		flag = 1
		break

	current *= 10
	current += 7
	current %= k
	count += 1

if flag == 1:
	print(count)

else:
	print(-1)

Submission status: Accepted

Solution code:
K = int(input())

history = {}
tmp = 0
for i in range(1, K + 2):
    tmp = (tmp * 10 + 7) % K
    key = str(tmp)
    if tmp == 0:
        ans = i
        break
    elif history.setdefault(key, False) == True:
        ans = -1
        break
    else:
        history[key] = True
        continue

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
table = [False] * k
i = 1
now = 7
while True:
    if now % k == 0:
        print(i)
        exit()
    if table[now % k]:
        print(-1)
        exit()
    table[now % k] = True
    now = (now * 10 + 7) % k
    i += 1

Submission status: Accepted

Solution code:
k = int(input())
x, i = 0, 0
r = set()
while True:
    x = (x * 10 + 7) % k
    i += 1
    if x == 0:
        break
    if x in r:
        print(-1)
        quit()
    r.add(x)
print(i)

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    # T = A*K = 77...7
    K = read_int()
    seen = set()
    T = 7
    i = 1
    while T%K not in seen:
        if T%K == 0:
            return i
        seen.add(T%K)
        T = (T%K)*10+7
        i += 1
    return -1


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    if N%2==0: 
        print(-1)
        return #10の倍数も含まれる
    cnt=7%N
    if cnt==0:
        print(1)
        return
    for i in range(2,10**7):
        cnt=cnt*10+7
        cnt%=N
        if cnt==0:
            print(i)
            return
    print(-1)
#%%submit!
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class Modulo_Error(Exception):
    pass

class Modulo():
    def __init__(self,a,n):
        self.a=a%n
        self.n=n

    def __str__(self):
        return "{} (mod {})".format(self.a,self.n)

    #+,-
    def __pos__(self):
        return self

    def __neg__(self):
        return  Modulo(-self.a,self.n)

    #等号,不等号
    def __eq__(self,other):
        if isinstance(other,Modulo):
            return (self.a==other.a) and (self.n==other.n)
        elif isinstance(other,int):
            return (self-other).a==0

    def __neq__(self,other):
        return not(self==other)
    
    #加法
    def __add__(self,other):
        if isinstance(other,Modulo):
            if self.n!=other.n:
                raise Modulo_Error("異なる法同士の演算です.")
            return Modulo(self.a+other.a,self.n)
        elif isinstance(other,int):
            return Modulo(self.a+other,self.n)

    def __radd__(self,other):
        if isinstance(other,int):
            return Modulo(self.a+other,self.n)
        
    #減法
    def __sub__(self,other):
        return self+(-other)

    def __rsub__(self,other):
        if isinstance(other,int):
            return -self+other
        
    #乗法
    def __mul__(self,other):
        if isinstance(other,Modulo):
            if self.n!=other.n:
                raise Modulo_Error("異なる法同士の演算です.")
            return Modulo(self.a*other.a,self.n)
        elif isinstance(other,int):
            return Modulo(self.a*other,self.n)
        
    def __rmul__(self,other):
        if isinstance(other,int):
            return Modulo(self.a*other,self.n)
        
    #Modulo逆数
    def Modulo_Inverse(self):
        x0, y0, x1, y1 = 1, 0, 0, 1
        a,b=self.a,self.n
        while b != 0:
            q, a, b = a // b, b, a % b
            x0, x1 = x1, x0 - q * x1
            y0, y1 = y1, y0 - q * y1

        if a!=1:
            raise Modulo_Error("{}の逆数が存在しません".format(self))
        else:
            return Modulo(x0,self.n)

    #除法
    def __truediv__(self,other):
        return self*(other.Modulo_Inverse())
    
    def __rtruediv__(self,other):
        return other*(self.Modulo_Inverse())

    #累乗
    def __pow__(self,m):
        u=abs(m)

        r=Modulo(1,self.n)

        while u>0:
            if u%2==1:
                r*=self
            self*=self
            u=u>>1

        if m>=0:
            return r
        else:
            return r.Modulo_Inverse()

    #根号
    def sqrt(self):
        if self==0:
            return self
        elif self.n==2:
            return self
        elif self.n%4==3:
            return self**((self.n+1)//4)
        else:
            p=self.n
            u=2
            s=1
            while (p-1)%(2*u)==0:
                u*=2
                s+=1

            z=Modulo(2,p)
            while z**((p-1)//2)!=-1:
                z+=1

            q=(p-1)//u
            m=s
            c=z**q
            t=self**q
            r=self**((q+1)//2)

            while m>1:
                k=1
                d=t*t

                while d!=1:
                    k+=1
                    d*=d
                    print(m,k)
                b=Modulo(2,p)**(2**(m-k-1))
                c,t,r,m=b*b,t*b*b,r*b,k
            return r

#=======================================
K=int(input())
X=-1
G=Modulo(1,K)
Z=Modulo(0,K)

for i in range(1,K+1):
    Z+=7*G
    G*=10

    if Z==0 and X==-1:
        X=i
print(X)

Submission status: Accepted

Solution code:
import sys, math

if(__name__ == "__main__"):
    """
    N, D = map(int, input().strip().split() )
    D_sq = D**2
    xy_list = []
    for i in range(N):
        xy = list( map(int, input().strip().split() ) )
        xy_list.append(xy)
    """
    K = int( input().strip() )

    Remainder = 7%K
    if(Remainder==0):
        print(1)
    else:
        Flag = True
        Times = 1
        for i in range(K):
            Remainder=(10*Remainder+7)%K
            Times += 1

            if(Remainder==0):
                print(Times )
                Flag = False
                break

        if(Flag==True):
            print(-1)

Submission status: Accepted

Solution code:
K = int(input())

a = 7
flag = False

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
mod1=0.7
mod2=0
ans=-1
for i in range(1,10**6+1):
  mod1=(mod1*10)%n
  mod2=(mod1+mod2)%n
  if mod2==0:
    ans=i
    break
print(ans)

Submission status: Accepted

Solution code:
k=int(input())
dp=[0]*1000001
val=0
cnt=0
flag=1
for i in range(0,1000000):
    cnt+=1;
    val=val*10+7
    if(val%k==0):
        break
    val=val%k
    if(dp[val]==1):
        flag=0;
        break;
    else:
        dp[val]=1
if flag==0:
    print(-1)
else:
    print(cnt)



# 7
# 77
# 7*10 + 7
# 7*100+7*10+7

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import bisect
import math
import fractions
import sys
import copy


def L(): return sys.stdin.readline().split()


def I(): return int(sys.stdin.readline().rstrip())


def S(): return list(sys.stdin.readline().rstrip())


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def IR(n): return [I() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def LIR1(n): return [LI1() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def LR(n): return [L() for _ in range(n)]


alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007


def main():
    K = I()
    ans = 1
    tmp = 7

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

    while tmp % K != 0:
        tmp *= 10
        tmp += 7
        tmp %= K
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
def resolve():
    K = int(input())
    lst = [-1]*K
    st = 7
    count =1
    while True:
        st %= K
        if st ==0:
            print(count)
            return
        if lst[st]!=-1:
            print(-1)
            return
        lst[st]=1
        st = (st*10+7)%K
        count +=1
resolve()

Submission status: Accepted

Solution code:
K=int(input())
ans=-1
count=1
a=7
amari=[0]*K
while 1:
    b=a%K
    if b==0:
        ans=count
        break
    if amari[b]==1:
        break
    amari[b]=1
    count+=1
    a=10*b+7
print(ans)

Submission status: Accepted

Solution code:
K  = int ( input().strip() ) ;
v = 0 ;
r = -1 ;
for x in range (  1 ,  K + 1 ) :
	v = ( v * 10 + 7  ) % K ; 
	if v == 0 :
		r = x ;
		break ;
print ( r ) ;

Submission status: Accepted

Solution code:
def solve(K):
 # if K % 2 == 0:
  #  return -1
 # if K % 5 == 0:
 #   return -1
  current = 7 % K
  for i in range(K + 10):
    if current == 0:
      return i+1
    current = (current * 10 + 7 )% K
  return -1

K = int(input())
print(solve(K))

Submission status: Accepted

Solution code:
n = int(input().rstrip())
passed = set()

from sys import exit
cnt = 1
tmp = 7
while 1:
    if tmp % n == 0:
        print(cnt)
        exit()
    elif tmp not in passed:
        passed.add(tmp)
        cnt += 1
        tmp = (tmp*10+7) % n
    else:
        print(-1)
        exit()

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

K = int(input())

d = defaultdict(int)
dd = set()
num = 7
cnt = 1
if K == 7:
    print(1)
    exit()
while num % K != 0:
    num = num*10 + 7
    num %= K
    if num in dd:
        print(-1)
        exit()
    dd.add(num)
    cnt += 1
    # print(dd)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    NI = lambda : int(sys.stdin.readline())

    K = NI()
    ans = 0
    m = 0
    while True:
        m = (m * 10 + 7) % K
        ans += 1
        if m == 0 or ans > K: break
    if ans <= K:
        print(ans)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
dp =[0]
for i in range(10**6+1):
    dp.append((dp[-1]*10+7)%k)
    if dp[-1]==0:print(i+1);exit()
print(-1)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    k = int(readline())
    cur = 0

    for i in range(1, 10000001):
        cur *= 10
        cur += 7
        cur %= k
        if cur == 0:
            return print(i)

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
K = int(input())
flag = 0
num = 7
for i in range(10**6):
    if num % K == 0:
        print(i+1)
        flag = 1
        break
    num += 7*pow(10,i+1,K)
if flag == 0:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
MAX = pow(10,6)+10
#keta = 1
now = 0
SET = set([])
for i in range(MAX):
  now = (now*10+7)%K
  if now == 0:
    print(i+1)
    exit()
  else:
    if now in SET:
      print(-1)
      exit()
    else:
      SET.add(now)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
 
def main():
    k=int(input())
    ans=1
    amari=0
    for _ in range(10**6+5):
        amari = (amari*10+7)%k
        if amari==0:
            print(ans)
            break
        ans+=1
    else:
        print(-1)

 
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
K=int(input())

if K==1:
    print(1)
    exit()
if K==7:
    print(1)
    exit()
ans=1
MOD=set()

cur=7
while True:
    if cur==0:
        print(ans)
        exit()
    else:
        r=cur%K
        if r in MOD:
            print(-1)
            exit()
        else:
            MOD.add(r)
        cur=(cur*10+7)%K
        ans+=1

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
from math import gcd
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

K=int(input())
if K%7==0:
    K/=7
tmp=1%K
for i in range(1,10**7):
    if tmp==0:
        print(i)
        exit()
    tmp*=10
    tmp+=1
    tmp%=K
print(-1)