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())
x=i=0
while i<7e6:i+=1;x=(x*10+7)%k;x<1>exit(print(i))
print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

k = int(input())
'''if k == 7 or k == 1:
    print(1)
elif k % 2 == 0 or k % 5 == 0: print(-1)
else:
    if k % 7 == 0: k = k // 7
    mod = 9*k
    i = 1;
    result = 10;
    while result != 1:
        result = (result * 10) % mod
        i += 1
    print(i)'''
num = 7%k
soln = False
for i in range(1, k+1):
    if num == 0:
        print(i)
        soln = True
        break
    num= (num * 10 + 7) % k
if not soln:
    print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    mod, modt, ans = 7 % K, 7 % K, 1
    while mod != 0:
        modt = (modt * (10 % K)) % K
        mod, ans = (mod + modt) % K, ans + 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

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

mod = 7
cnt = 1
while True:
  if mod%k==0:
    print(cnt)
    exit()
    
  mod *= 10
  mod += 7
  cnt += 1
  mod %= k

Submission status: Accepted

Solution code:
K = int(input())
seven = 7
count = 0

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

        # これだと10^5以降の計算が遅くなる。countのせい？？
        # count += 1
        # seven = seven + 7 * (10 ** count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
if n==0:
    print(0)
if n%2==0:
    print(-1)
elif n%5==0:
    print(-1)
else:
    k=7
    l=1
    k%=n
    while k!=0:
        l+=1
        k*=10
        k+=7
        k%=n
        #print(k)
    print(l)

Submission status: Accepted

Solution code:
K = int(input())

memo = set()
repunit = 7%K
n = 1
while True:
    if repunit == 0:
        print(n)
        exit()
    else:
        if repunit in memo:
            print(-1)
            exit()
        else:
            memo.add(repunit)
    repunit = (repunit*10 + 7)%K
    n += 1

Submission status: Accepted

Solution code:
k = int(input())

m = 0

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

print(-1)

Submission status: Accepted

Solution code:
import sys

K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    sys.exit()
if K % 7 == 0:
    K //= 7
count = 1
mod = 1
sum = 1
while sum % K != 0:
    mod = (mod * 10) % K
    sum += mod
    sum = sum % K
    count += 1
print(count)

Submission status: Accepted

Solution code:
k = int(input())

m = 0

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

print(-1)

Submission status: Accepted

Solution code:
"""
    Satwik_Tiwari ;) .
    2ND AUGUST , 2020  - SUNDAY
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================
#fast I/O region
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")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
  def wrapped_func(*args, **kwargs):
    if stack: return f(*args, **kwargs)
    to = f(*args, **kwargs)
    while True:
      if type(to) is GeneratorType:
        stack.append(to)
        to = next(to)
        continue
      stack.pop()
      if not stack: break
      to = stack[-1].send(to)
    return to
  return wrapped_func
#### END ITERATE RECURSION ####

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))

def solve():
    k = int(inp())
    curr = str(7%k)
    for i in range(k):
        if(int(curr)%k==0):
            print(i+1)
            return
        else:
            curr+='7'
            curr = str(int(curr)%k)
    print(-1)


testcase(1)
# testcase(int(inp()))

Submission status: Accepted

Solution code:
K = int(input())

ans = 1
X = 7
cnt = K

for _ in range(1000000):
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7

if x != 0:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())
c = 0
start = 7%k
while c<=k:
    if start == 0:
        break
    c+=1
    start = (start*10+7)%k
if c>k:
    print(-1)
else:
    print(c+1)

Submission status: Accepted

Solution code:
K = int(input())
 
ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 
 
if x != 0:
    print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
K = int(input())

ans = 1
X = 7
cnt = K

while ans <=K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7

if x != 0:
    print(-1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def I(): return int(input())


def main():
    K = I()
    if K % 2 == 0 or K %  5 == 0:
        print(-1)
        exit()
    if K % 7 == 0:
        K = 9*K//7
    else:
        K = 9*K
    amari = 1
    for i in range(10**6):
        amari = amari*10 % K
        if amari == 1:
            print(i+1)
            exit()
    print(-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
#from __future__ import print_function, division    #while using python2

def is_valid(x):
    # print(x)
    # input()
    return str(x).count('7') == len(str(x))

def main():
    #sys.stdin = open('input.txt', 'r')
    #sys.stdout = open('output.txt', 'w')

    k = int(input())
    s = 7

    for i in range(1, int(1e6)+5):
        if s % k == 0:
            print(i)
            return
        s = (s * 10 + 7) % k
    print(-1)

#------------------ Python 2 and 3 footer by Pajenegod and c1729-----------------------------------------
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

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

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            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')

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
from numba import njit
k = int(input())

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

@njit
def fun():
    m = 1
    for i in range(1, l + 1):
        m = m * 10 % l
        if m == 1:
            print(i)
            break
    else:
        print(-1)

fun()

Submission status: Accepted

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


else:
    print("-1")

Submission status: Accepted

Solution code:
K = int(input())

ans = 1
X = 7
cnt = K
while ans <= K:
    x = X % K
    if x == 0:
        print(ans)
        break
    else:
        ans += 1
        X = x*10 + 7 

if x != 0:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
 
s = 7
for i in range(1, k+1):			# rangeの上限がk
    if s % k == 0:
        print(i)
        break
    s = (s * 10 + 7) % k		# %kが難しい
else:                           # for文にもelseが使える
    print(-1)

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    num = 1
    n = 7

    if (k % 2 == 0):
        print(-1)
        return
    
    for i in range(1000000):
        if (n % k == 0):
            print(num)
            return
        else:
            n = (n*10 + 7) %k
            num += 1
    print(-1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
i = 1
y = 1
if K== 1:
  print(1)
elif K%2 == 0 or K%5 == 0:
  print(-1)
#elif K%3 == 0:
#  print(3)
elif K== 7:
  print(1)
else:
  if K%7 == 0:
    K = K//7
  while True:
    i += 1
    y = ((y*10)%K) + 1
    y = y%K
    if y == 0:
      break
  print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

now=1
cnt=1
mae=0
if k%2==0:
  print(-1)
  sys.exit()


for i in range(2*10**6):
  now=(10*mae+7)%k
  if now%k==0:
    print(i+1)
    sys.exit()
  else:
    mae=now%k

print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

  
  
print(-1)

Submission status: Accepted

Solution code:
from math import log10

K = int(input())
  
def find(K):
  if K % 2 == 0 or K % 5 == 0:
    return -1
  
  if K % 7 == 0:
    L = K * 9 // 7
  else:
    L = K * 9

  count = max(int(log10(L)), 1)
  
  quotient = 10**count % L
  
  while True:
    if quotient == 1:
      return count
    quotient = quotient * 10 % L
    count += 1
    
    
print(find(K))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

count = 1
m = 7 % K
s = set()
while 1:
    if m == 0:
        print(count)
        break
    if m in s:
        print(-1)
        break
    count += 1
    s.add(m)
    m = (m * 10 + 7) % K

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

mod = [1]
i = 1


while True:
    mod.append((mod[i-1]*10)%L)
    if mod[i] == 1:
        print(i)
        break
    if i > K:
        print(-1)
        break
    i += 1

Submission status: Accepted

Solution code:
import sys

def resolve():
    readline=sys.stdin.readline
    k=int(readline())
    to=10**6
    svn=[0]*to
    svn[0]=7%k
    if svn[0]==0:
      print(1)
      return
    for i in range(1,to):
      svn[i]=(svn[i-1]*10)%k
    for i in range(1,to):
      svn[i]+=svn[i-1]
      if svn[i]%k==0:
        print(i+1)
        return
      
    print(-1)
    return
resolve()

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
k = int(input())

digits = 1
remainder = 7 % k
while digits <= 1000000:
    if remainder == 0:
        print(digits)
        quit()
    digits += 1
    remainder = (remainder * 10 + 7) % k
print(-1)

Submission status: Accepted

Solution code:
k=int(input())
if (k%2)*(k%5)<1: exit(print(-1))
a,t,m=1,7,7
while m%k:
  a+=1
  t=t*10%k
  m+=t
print(a)

Submission status: Accepted

Solution code:
n=int(input())
if n%2==0 or n%5==0:
    print(-1)
else:
    count=1
    flag=0
    num=7
    mod=7%n
    while flag==0:
        if mod==0:
            flag=1
        else:
            mod=(mod*10+7)%n
            count=count+1
    print(count)

Submission status: Accepted

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

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

    for i in range(1000000):
        if (n%k == 0):
            print(num)
            return
        else:
            n = (n*10 + 7)%k
            num += 1

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

Submission status: Accepted

Solution code:
import sys

k = int(input())
n = 7
counter = 1
remainders = set()

while True:
    remainder = n % k
    if remainder == 0:
        print(counter)
        sys.exit()
    if remainder in remainders:
        print(-1)
        sys.exit()
    remainders.add(remainder)
    
    n = remainder * 10 + 7
    counter += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def Ii():return int(sys.stdin.readline())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))

k = Ii()
if k%2 == 0 or k%5 == 0:
  print(-1)
  exit(0)
elif k%7 == 0:
  k = k//7
ans = 1
a = 10
mod = a%(9*k)
while mod != 1:
  mod *= 10
  mod = mod%(9*k)
  ans += 1
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def main():
    k = int(input())
    mod = 7
    cnt = 1

    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)

main()

Submission status: Accepted

Solution code:
import math
t = int(input())
if t%2==0 or t%5==0:
    print(-1)
else:
    i=1
    s=7%t
    while 1:
        if (s%t)==0:
            print(i)
            break
        i += 1

        s = (s * 10 + 7)%t

        continue

Submission status: Accepted

Solution code:
import math

k = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

K = int(sys.stdin.readline().strip())

exists = set()
v = 7
if v % K == 0:
    print(1)
    sys.exit()
v %= K
for i in range(K):
     v = (v * 10 + 7) % K
     if v == 0:
        print(i+2)
        sys.exit()
     if v in exists:
        print(-1)
        sys.exit()
     exists.add(v)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())

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

else:
    num=7%k
    ans=1

    while num != 0:

        num=(num*10+7)%k
        ans+=1

    print(ans)

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

k = inint()

x = 7%k

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

Submission status: Accepted

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

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

if K%7==0:
	K=K//7

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

# 2darray [[0] * 4 for i in range(3)]
# import itertools

Submission status: Accepted

Solution code:
def solve(n):
  s = set()
  i = 1;
  x = 7 % n
  while (not (x in s)):
    if x == 0:
      return i;
    s.add(x)
    x = x * 10 + 7;
    x %= n;
    i += 1
  return -1

if __name__ == '__main__':
  n = int(input())
  if n == 2 or n == 5:
    print(-1)
  else:
    print(solve(n))

Submission status: Accepted

Solution code:
K = int(input())

A = 7
ans = 1

while ans <= K:
  if K % 2 == 0 or K % 5 == 0:
    print('-1')
    break
  if A % K == 0:
    print(ans)
    break
  A = (A * 10 + 7) % K
  ans = ans + 1

Submission status: Accepted

Solution code:
K= int(input())

visited = set()
remainder = 7
counter = 1

while True:
    remainder = remainder % K
    if remainder in visited:
        print(-1)
        exit()
    if remainder == 0:
        print(counter)
        exit()
    else:
        visited.add(remainder)
        remainder = 10 * remainder + 7
    counter += 1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
"""
数列777...は奇数故，Kが偶数だったら×

"""
from numba import njit


@njit(cache=True)
def func(a, b):
    return a * b


def main():
    import sys
    input = sys.stdin.readline

    K = int(input())

    # mod Kを考える(mod=module(剰余))
    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())

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

Submission status: Accepted

Solution code:
#  mod Nの取りうる値の上限はN-1なのでN-1回のループで解が出なければ-1でいい
#  modの値が同じになった場合ループになるためexitする

K = int(input())

mod = 7 % K

res = {}

i = 1

while not mod in res:
    if mod == 0:
        print(i)
        exit()

    res[mod] = 1
    mod = (mod * 10 + 7) % K
    i += 1

print(-1)

Submission status: Accepted

Solution code:
s = 7
a = int(input())

for i in range(10**6):
    if s%a == 0:
        print(i+1)
        exit()
    s = (s*10+7) % a
print(-1)

Submission status: Accepted

Solution code:
k = int(input())

x = 7

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

Submission status: Accepted

Solution code:
K = int(input())
if K%5==0 or K%2==0:
    print(-1)
else:
    cnt=1
    ms = 7 % K
    while ms != 0:
        cnt+=1
        ms = (ms*10+7)%K

    print(cnt)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
K = int(input())

a = 7 % K

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

print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import time
import numpy
sys.setrecursionlimit(int(1e6))
#dprint = print
def dprint(*args):
    pass

k = list(map(int, input().split()))[0]

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

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

print(-1)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    from time import perf_counter
    s = perf_counter()
    ans = 1
    num = 7
    K = II()
    if K % 2 == 0:
        print(-1)
        return
    while perf_counter() - s < 1.9:
        if num % K == 0:
            print(ans)
            return
        else:
            num = (num*10+7)%K
            ans += 1
    print(-1)
    dbg(len(str(num)))
    return
        


    
main()

Submission status: Accepted

Solution code:
K = int(input())
MOD = 1000000007

r = 0
cnt = 0
x = 0
while x < 10 ** 6 + 1:
    r = r * 10 + 7
    r %= K

    if r % K == 0:
        print(cnt + 1)
        exit()

    cnt += 1
    x += 1

print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print('-1')
else:
    cnt = 1
    cur = 7
    while True:
        if cur % K == 0:
            print(cnt)
            break
        if cnt > K:
            print('-1')
            break
        cur = (cur * 10 + 7) % K
        cnt += 1

Submission status: Accepted

Solution code:
k = int(input())

if k == 1 or k == 7:
    print(1)

elif k % 2 != 0 and k % 5 != 0:
    if k % 7 == 0:
        l = 9 * k // 7
    else:
        l = 9 * k

    m = 10 % l
    for i in range(1,k + 3):
        if m * 10 % l == 1:
            print(i + 1)
            break
        else:
            m = m * 10 % l

else:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())

if k%2==0 or k%5==0:
    print('-1') 
else:
    a = 0
    for i in range(999983):
        a = (a*10+7) % k
        if a == 0:
            print(i+1)
            break
    else:
        print(-1)

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    count = 1
    num = 7
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        exit()
    while True:
        if num % k == 0:
            print(count)
            exit()
        num = (num*10+7) % k
        count += 1


if __name__ == '__main__':
    main()