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())
i = 1
x = 7 % k
seen = {x}
while x != 0:
	x = (10 * x + 7) % k
	i += 1
	if x in seen:
		print(-1)
		break
	seen.add(x)
else:
	print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())
ans=0
dev=7
while dev%k and ans <=k+3:
    ans+=1
    dev+=7*pow(10,ans,k)
    dev%=k
if ans==k+4:print(-1)
else:print(ans+1)

Submission status: Accepted

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

'''
Author: andyli
Time: 2020-08-02 19:55:49
'''

import os
from io import BytesIO, IOBase
import sys


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


# region fastio
BUFSIZE = 1048576


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)
def input(): return sys.stdin.readline().rstrip('\r\n')

# endregion


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    if K % 2 == 0:
        print(-1)
        exit()

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

k = I()
tmp = 0
for i in range(k+1):
    tmp += 7 * pow(10, i, k)
    tmp %= k
    if tmp % k == 0:
        print(i+1)
        quit()
print(-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve(K):
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return
    X = 7
    cnt = 1
    while True:
        if X % K == 0:
            print(cnt)
            return
        cnt += 1
        X = X * 10 + 7
        X %= K


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    K = Scanner.int()
    solve(K)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())
hist = set()

INF = 10**8

w = 0
for i in range(INF):
  w += 7 * pow(10,i,K)
  w %= K
  if w == 0:
    print(i+1)
    break
  else:
    if w in hist:
      print(-1)
      break
    else:
      hist.add(w)
      
#print(hist)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
def solve(k):
    x = 7
    checked = set()
    ans = 1
    while True:
        x %= k
        if x == 0:
            return ans
        if x in checked:
            return -1
        checked.add(x)
        x = x * 10 + 7
        ans += 1


k = int(input())
print(solve(k))

Submission status: Accepted

Solution code:
"""
                            pppppppppppppppppppp
                         ppppp  ppppppppppppppppppp
                      ppppppp    ppppppppppppppppppppp
                      pppppppp  pppppppppppppppppppppp
                      pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
       ppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppp
      pppppppppppppppppppppppppppppppppppppppppppppppp  ppppppppppppppppppppp
     ppppppppppppppppppppppppppppppppppppppppppppppppp  pppppppppppppppppppppp
    ppppppppppppppppppppppppppppppppppppppppppppppp    pppppppppppppppppppppppp
   pppppppppppppppppppppppppppppppppppppppppppppp     pppppppppppppppppppppppppp
  ppppppppppppppppppppppppppppppppppppppppppppp      pppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppppppp               pppppppppppppppppppppppppppppppp
  pppppppppppppppppppppppppppp     pppppppppppppppppppppppppppppppppppppppppppppp
  ppppppppppppppppppppppppppp    pppppppppppppppppppppppppppppppppppppppppppppppp
    pppppppppppppppppppppppp  pppppppppppppppppppppppppppppppppppppppppppppppppp
     ppppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppppp
      pppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppppp
       ppppppppppppppppppppp  ppppppppppppppppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppppp
                              pppppppppppppppppppppppppppppppp
                              pppppppppppppppppppppp  pppppppp
                              ppppppppppppppppppppp    ppppppp
                                 ppppppppppppppppppp  ppppp
                                    pppppppppppppppppppp
"""


import sys
from functools import lru_cache, cmp_to_key
from collections import defaultdict as dd, deque, Counter as C
from bisect import bisect_left as bl, bisect_right as br, bisect
from math import sqrt
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var, end="\n"): sys.stdout.write(str(var)+end)
def outa(*var, end="\n"): sys.stdout.write(' '.join(map(str, var)) + end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n = int(data())
if n % 2 == 0 or n % 5 == 0:
    print(-1)
f = 7
cnt = 1
while cnt <= 2 * 10 ** 6:
    if f % n == 0:
        out(cnt)
        break
    cnt += 1
    f = f * 10 + 7
    f %= n

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = input()
v = 7 % k
l = 1

for _ in xrange(k+10):
    if v != 0:
        v = (v * 10 + 7) % k
        l += 1
    else:
        break

if v == 0:
    print l
else:
    print -1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
m = [False] * k
s = 0
d = 7 % k
i = 0
while True:
  s = (s + d) % k
  d = d * 10 % k
  i += 1
  if s == 0:
    print(i)
    break
  if m[s]:
    print(-1)
    break
  m[s] = True

Submission status: Accepted

Solution code:
K = int(input())

ans = -1
cur = 7
r = 0

for i in range(K):
    r += cur % K
    r %= K
    if r == 0:
        ans = i + 1
        break
    cur *= 10
    cur %= K

print(ans)

Submission status: Accepted

Solution code:
import sys

K = int(input())
if K%7==0:
    K = K//7

n = 0
for i in range(1, K+1):
    n = (10*n+1)%K
    if n==0:
        print(i)
        sys.exit()
print(-1)

Submission status: Accepted

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

if K == 1:
    print(1)
    exit(0)

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

print(-1)

Submission status: Accepted

Solution code:
from collections import defaultdict

k = int(input())

ms = defaultdict(int)

ans = 1
i = 7
while True:
    if i % k == 0:
        print(ans)
        exit()
    i = (i * 10 + 7) % k
    if ms[i] > 0:
        print(-1)
        exit()
    ms[i] += 1
    ans += 1

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().rstrip()


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

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

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



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

A = [0 for _ in range(K)]

a = 0
i = 1
while True:
  a *= 10
  a += 7
  a %= K
  if A[a] > 0: # きたことのある数
    print(-1)
    sys.exit()
  if a == 0:
    print(i)
    sys.exit()
  A[a] = i
  i += 1

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
x = 7
ans = 1
s = set()
while x%k != 0:
    ans += 1
    x = (x*10%k+7)%k
    if x in s:
        ans = -1
        break
    s.add(x)
print(ans)

Submission status: Accepted

Solution code:
K = int(input())

X = 0

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    K = NI()
    tmp = 7
    for i in range(1000005):

        if tmp % K == 0:
            print(i+1)
            exit()
        tmp = tmp * 10 + 7
        tmp = tmp % K
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    K = int( input())
    now = 7
    now %= K
    for i in range(10**7):
        if now == 0:
            print(i+1)
            return
        now = (now*10+7)%K
    print("-1")
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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 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:
def examA():
    X = I()
    if X<30:
        ans = "No"
    else:
        ans = "Yes"
    print(ans)
    return

def examB():
    N, D = LI()
    cnt = 0
    for _ in range(N):
        x, y = LI()
        if x**2+y**2<=D**2:
            cnt += 1
    ans = cnt
    print(ans)
    return

def examC():
    N = 10**7
    K = I()
    cur = 0
    now = 1
    ans = -1
    for i in range(N):
        cur += 7 * now
        cur %= K
        if cur==0:
            ans = i+1
            break
        now *= 10
        now %= K
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep,alphabet_convert
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

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

def main():
    INF = 999999999999999999999999
    MOD = 10**9+7

    k = int(input())
    if k%2==0 or k%5==0:
        print(-1)
        exit()
    
    x = 7
    ans = 1
    while x % k != 0:
        x = (x*10 + 7) % k
        ans += 1
    print(ans)
main()

Submission status: Accepted

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
k=int(input())
cur=0
for i in range(10**6+1):
  cur=(cur+7*pow(10,i,k))%k
  if cur==0:
    print(i+1)
    break
else:
  print(-1)

Submission status: Accepted

Solution code:
k = int(input())

r = set()
x = 7
i = 1
while True:
    rr = x % k
    if rr == 0:
        print(i)
        break
    if rr in r:
        print(-1)
        break
    x = (x * 10 + 7) % k
    i += 1
    r.add(rr)

Submission status: Accepted

Solution code:
n = int(input())

now_mod = 0

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

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

print(-1)
exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

ans = 1
n = 7%K
for _ in [0]*K:
    if n == 0:
        print(ans)
        break
    n = (n*10+7)%K
    ans += 1
else:
    print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

else:
    print('-1')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

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

print(-1)

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    k=INT()
    temp=7
    ans=-1
    for i in range(k):
        if i==0:
            temp=temp%k
        else:
            temp=(temp*10+7)%k

        if temp==0:
            ans=i+1
            break

    print(ans)
if __name__=='__main__':
    do()

Submission status: Accepted

Solution code:
import math
import pprint
import fractions
import collections
import itertools
from decimal import *
from collections import deque
from bisect import *
K=int(input())
flag=0
cnt=0
ans=0
for i in range(K):
    cnt=(cnt+7*pow(10,i,K))%K
    if cnt==0:
        flag=1
        ans=i+1
        break
if flag==0:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()
c = 1
d = 7 % K
D = defaultdict(int)
while True:
    if d == 0:
        print(c)
        exit()
    if D[d] == 1:
        print(-1)
        exit()
    D[d] += 1
    c += 1
    d = (d * 10 + 7)%K

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
ans = 1
now = 7
while now % K != 0:
    ans += 1
    now *= 10
    now += 7
    now %= K
    if ans > 999982:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

Solution code:
k = int(input())

x = 7 % k
s = set()
for i in range(k):
    if x % k == 0:
        ans = i + 1
        break
    if x in s:
        ans = -1
        break

    s.add(x)
    x = 10 * x + 7
    x %= k

print(ans)

Submission status: Accepted

Solution code:
import math
import sys
from itertools import permutations
input = sys.stdin.readline

K=int(input())

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

print(ans)

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

Submission status: Accepted

Solution code:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def main():
    k = int(input())
    a = 7
    x = 1
    while a % k != 0 and x <= k + 10:
        x += 1
        a = (a * 10 + 7) % k
    if x < k + 5:
        print(x)
    else:
        print(-1)
main()

Submission status: Accepted

Solution code:
k=int(input())

tmp=7
flag=False

for i in range(1,k+1):
    if tmp%k==0:
        print(i)
        flag=True
        break
    tmp=tmp*10+7
    tmp%=k
if flag==False:
    print(-1)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

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

Submission status: Accepted

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

K = int(input())

A = [-1]*(K+1)

ans = -1
t = 7 % K
for s in range(K+1):
    if t == 0:
        ans = s + 1
        break
    if A[t] != -1:
        break
    A[t] = 1
    t = (t*10 + 7) % K

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()

tmp = 7
ans = 1
p = 1
mo = tmp%K
checked = [0]*(10**6+1)
checked[mo] = 1
while mo != 0:
    mo = mo + 7*pow(10, p, K)
    mo %= K
    p += 1
    if checked[mo]:
        print(-1)
        break
    checked[mo] = 1
else:
    print(p)

Submission status: Accepted

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

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

    r = 7 % K
    idx = 1
    while r:
        r = (r * 10 + 7) % K
        idx += 1
        if idx > K:
            print(-1)
            return

    print(idx)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	K = int(input())
	val = 0
	for i in range(10 ** 6 + 1):
		val = (val * 10 + 7) % K
		if val % K == 0:
			print(i + 1)
			return

	print(-1)


if __name__ == '__main__':
	main()

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

K = I()

now = 7%K
count = 1

while now:
  now *= 10
  now += 7
  now %= K
  count += 1
  if count > K*2:
    print(-1)
    exit()
  
print(count)

Submission status: Accepted

Solution code:
k = int(input())
rem = 7%k
alreadys = [False]*k
alreadys[rem] = True

ans = 1
while True:
    if rem == 0:
        print(ans)
        exit()
    ans += 1
    rem = (rem*10+7)%k
    if alreadys[rem]:
        print(-1)
        exit()
    alreadys[rem] = True

Submission status: Accepted

Solution code:
k = int(raw_input())
seen = set()
compute = 7 % k
count = 1
while(compute!= 0 and compute not in seen):
	count += 1
	seen.add(compute)
	compute *= 10
	compute += 7
	compute %= k
print count if compute == 0 else -1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
k = int(input())
ans = 1
p = 7
used = {p: True}
while True:
    if p % k == 0:
        print(ans)
        exit()
    p = (p * 10 + 7) % k
    if p in used:
        print(-1)
        exit()
    used[p] = True
    ans += 1

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


K = ni()

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

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

Submission status: Accepted

Solution code:
K = int(input())

b = 0
for i in range(1, 10**6+9):
    x = (b*10+7)%K
    if x == 0:
        print(i)
        exit()
    b = x

print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

print(i)

Submission status: Accepted

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

import sys
input=sys.stdin.readline

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

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