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:
import math
from functools import reduce
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def repfunc(x,y):
    a=x-1
    for i in range(1,x):
        if y%i==0 and (pow(10,i)-1)%x==0:
            a=i
            break
    return a


k=int(input())
res=1
ans1=0
ans2=0
if k%7==0:
    k//=7
if k%2==0 or k%5==0:
    print(-1)
elif k ==1:
    print(1)
else:
    c=collections.Counter(prime_factorize(k))
    c2=list(c.keys())
    d=[0 for i in range(len(c2))]
    for i in range(len(c2)):
        if c2[i]==3:
            d[i]=pow(3,c[3])
        else:
            d[i]=repfunc(pow(c2[i],c[c2[i]]),pow(c2[i],c[c2[i]]-1)*(c2[i]-1))
    print(lcm_list(d))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N=int(sys.stdin.readline().strip())

a=0
for i in range(10**6):
    a+=7*pow(10,i,N)
    if a%N==0:
        print i+1
        quit()
else:
    print -1

Submission status: Accepted

Solution code:
k = int(input())
ans = 0
now = 7
if k == 1 or k == 7:
    now = 0
while True:
    if ans > k:
        print(-1)
        break
    elif now == 0:
        print(ans+1)
        break
    else:
        now = (now*10 + 7) % k
        ans += 1

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

K = int(input())
cnt = 0
now = 0
if K%2==0:
    print(-1)
    exit()
s = set([0])
for _ in range(10**6+5):
    now += pow(10, cnt, K)*7
    now %= K
    if now==0:
        print(cnt+1)
        break
    s.add(now)
    cnt += 1
else:
    print(-1)

Submission status: Accepted

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

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

k = int(readline())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
count = 1
x = 7
while x % k != 0 and count <= k:
    count += 1
    x = (10 * x + 7) % k

if x % k == 0:
    print(count)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

x = 7 % K
i = 1
while True:
    if x == 0:
        print(i)
        exit()
    x = (x * 10 + 7) % K
    i += 1
    if i > 10**6:
        print(-1)
        exit()

Submission status: Accepted

Solution code:

def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
count = 0
ans = -1

K = i()
N = "7"
s = 10
if K == 7 or K == 1:
    print(1)
    exit()
if K % 2 == 0:
    print(-1)
    exit()
mod = 7 % K

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

Submission status: Accepted

Solution code:
from sys import stdin

def main():

    input = stdin.readline

    K = int(input())

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

    seven_len = 0

    for i in range(10 ** 7):

        seven_len = (seven_len * 10 + 7) % K
        if seven_len == 0:
            print(i+1)
            return


    print("-1")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

def make_num(K=K):
    n = 0
    for c in range(1, K+1):
        n = (n * 10 + 7) % K
        if n % K == 0:
            return c

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    K = int(input())
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return True
    ans = 0
    K1 = K % 10
    t = K
    while t:
        # print(ans)
        for i in range(10):
            if (t + K1 * i) % 10 == 7:
                break
        else:
            ans = -1
            break
        t = t + K * i
        while t % 10 == 7:
            t //= 10
            ans += 1
            
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
count = 0
ans = -1

K = i()
N = "7"
s = 10
if K == 7 or K == 1:
    print(1)
    exit()
if K % 2 == 0:
    print(-1)
    exit()
mod = 7 % K

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)


def solve(k):
  x = 0
  for i in range(k):
    x += 7*pow(10,i,k)
    x %= k
    if x == 0:
      return i+1
  return -1



def main():
  K = int(input())
  # N,M = map(int,input().split())
  # a = list(map(int,input().split()))
  print(solve(K))
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
k=input()
if int(k)%2==0:
    print(-1)
else:
    s=7
    count=1
    flag=0
    while 1:
        if s%int(k)==0:
            print(count)
            break
        if count>int(k):
            print(-1)
            break
        s=(s%int(k))*10+7
        count+=1

Submission status: Accepted

Solution code:
K = int(input())


if K%2==0 or K%5==0:
    count = -1
else:
    flag=0
    mod = 7
    count = 1
    while mod%K!=0:
        count += 1
        mod = (mod*10+7) % K

print(count)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
k = int(input())
ans = 0
now = 7
while True:
    ans += 1
    now %= k
    if now == 0:
        print(ans)
        exit()
    now = now * 10 + 7
    if ans == 1000000:
        print(-1)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
m = 7
i = 1
while True:
  m = m%k
  if(m==0):
    print(i)
    break  
  if(i>k):
    print("-1")
    break
  m *= 10
  m += 7
  i += 1

Submission status: Accepted

Solution code:
K = int(input())
ans = -1
if K%2 == 0:
    pass
elif K%5 == 0:
    pass
else:
    num = 7
    ans = 0
    while True:
        ans += 1
        if num % K == 0:
            break
        else:
            num = (num * 10 + 7)%K
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())
a=7
for i in range(10**6):
    if a%k==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)
    exit()
r = 0
for i in range(1, k+1):
    r = (r * 10 + 7) % k
    if r == 0:
        print(i)
        break
else:
    print(-1)

Submission status: Accepted

Solution code:

k = int(input())
if k % 2 == 0:
    print("-1")
    exit()
if k == 1 or k == 7:
    print("1")
    exit()

seven_i = 7
for i in range(1,10**6):
    seven_i = seven_i*10+7
    seven_mod = seven_i % k

    if seven_mod == 0:
        print(i+1)
        exit()
    seven_i = seven_mod
print("-1")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

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

print(-1)

Submission status: Accepted

Solution code:
k = int(input())
if k==1 or k==7:
  print(1)
elif k%2==0:
  print(-1)
else:
  cnt = 1
  pre = 7
  while(True):
    surp = (pre*10+7)%k
    cnt += 1
    if surp==0:
      break
    if cnt>1000000:
      cnt = -1
      break
    pre = surp
  print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Accepted

Solution code:
import sys

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

def main():

    K = int(input())

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

    ans = 1
    X = 7
    count = K
    while count > 0:
        mod = X % K
        if mod == 0:
            break
        else:
            ans += 1
            X = mod * 10 + 7
            count -= 1
    print(ans if count > 0 else -1)
        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())
MOD = 10 ** 9 + 7

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

seven = 0
cnt = 0
mod = 0
for _ in range(10**7):
    mod = (mod * 10 + 7) % K
    if mod % K == 0:
        print(cnt+1)
        exit()
    if cnt > 10 ** 6:
        print('-1')
        exit()
    cnt += 1

Submission status: Accepted

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


def main():
    k = int(input())
    num = 7
    d = 1
    for i in range(10**6):
        if num % k == 0:
            print(d)
            return
        num = (num*10 + 7) % k
        d += 1
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())

#偶数、5の倍数はありえない
if(K % 2 == 0):
    print(-1)
    exit()

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

ans = 1
tmp = 7
for i in range(1*10**6):
    if tmp % K == 0:
        print(ans)
        exit()
    
    hoge = tmp % K
    ans += 1
    tmp = hoge * 10 + 7
#    print(ans, tmp)

print(-1)

Submission status: Accepted

Solution code:
k = int(input())

m = 7
mm = set()

i = 1
while True:
    m = m % k
    if m == 0:
        print(i)
        exit(0)
    if m in mm:
        break
    mm.add(m)
    i += 1
    m = m * 10 + 7

print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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
    while 1:
 
        if s%t==0:
            print(i)
            break
 
        else:
            i += 1
            s = (s * 10 + 7) % t
            continue

Submission status: Accepted

Solution code:
# # 1 <= K <= 10^6
# K = int(input())
# max_K = pow(10,6)
#
# import math
#
# #最大公約数
# for i in range(0,)
# math.gcd(101, 7777)
#
#
# row = ''
# for i in range(0,max_K):
#     row = row + '7'
#     n_row = int(row)
#     print(n_row)
#
#     if n_row % K == 0:
#         print(i + 1)
#         break
#     elif i == max_K:
#         print("-1")

k = int(input())
if k==1 or k==7:
  print(1)
elif k%2==0:
  print(-1)
else:
  cnt = 1
  pre = 7
  while(True):
    surp = (pre*10+7)%k
    cnt += 1
    if surp==0:
      break
    if cnt>1000000:
      cnt = -1
      break
    pre = surp
  print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())
if k==1 or k==7:
    print(1)
    exit()

ans = 1
amari = 7%k
s = amari

for i in range(k):
    ans += 1
    amari = amari*10 % k
    s += amari
    s %= k
    if s==0:
        print(ans)
        exit()
    
print(-1)

Submission status: Accepted

Solution code:
K = int(input())

cycle = set()
if K % 2 == 0:
    print(-1)
else:
    n = 7
    i = 1
    while 1:
        if n in cycle:
            i = -1
            break
        if n % K == 0:
            break
        cycle.add(n)
        n = (n * 10 + 7) % K
        i += 1
       
    print(i)

Submission status: Accepted

Solution code:
'''     ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     '''


# [temp1.py] => [29-07-2020 @ 10:25:10] 
# Author & Template by : Udit "luctivud" Gupta
# https://www.linkedin.com/in/udit-gupta-1b7863135/


import math;   from collections import *
import sys;    from functools import reduce
import time;   from itertools import groupby

# sys.setrecursionlimit(10**6)

def input()         : return sys.stdin.readline()
def get_ints()      : return map(int, input().strip().split())
def get_list()      : return list(get_ints())
def get_string()    : return list(input().strip().split())
def printxsp(*args) : return print(*args, end="")
def printsp(*args)  : return print(*args, end=" ")


DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)] 
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1),\
              (+1, +1), (+1, +0), (+1, -1), (+0, +1)]


CAPS_ALPHABETS = {chr(i+ord('A')) : i for i in range(26)}
SMOL_ALPHABETS = {chr(i+ord('a')) : i for i in range(26)}
INF = float('inf')


# Custom input output is now piped through terminal commands.
# for _test_ in range(int(input())): 

n = int(input())
mod = int(1e9) + 7
if (n % 2 == 0):
	print(-1)
else:
	ans = -1
	num = 7
	for i in range(1, n+1):
		if num % n == 0:
			ans = i
			break
		num = (num % n * 10) % n + 7
	print(ans)




# print("Time Elapsed: {}".format(float(S34p-S34t)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


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


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


K = z()
if K == 7:
    print(1)
    exit()

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

    t = (t * 10 + 7) % K

print(-1)

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
    while 1:

        if s%t==0:
            print(i)
            break

        else:
            i += 1
            s = (s * 10 + 7) % t
            continue

Submission status: Accepted

Solution code:
import sys
k = int(input())
seven = 7
ans = -1
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    sys.exit()
for cnt in range(1, 10**6):
    if seven % k == 0:
        ans = cnt
        break
    seven *= 10
    seven = (seven + 7) % k
print(ans)

Submission status: Accepted

Solution code:
k = int(input())
 
mx = 10**7
tmp = 0
flag = 0

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

if(flag == 0):
    print(-1)

Submission status: Accepted

Solution code:
K = int(input())

x = 7 % K

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    n = int(input())
    if n % 2 == 0 or n % 5 == 0:
        print('-1')
        return 0
    #mod表を作る
    time = 0
    mod_n = [7 % n]
    while(time < n + 5):
        next_mod_n = mod_n[time] * 10 % n
        if next_mod_n == mod_n[0]:
            break
        mod_n.append(next_mod_n)
        time += 1
    #print(mod_n)
    
    ans = 1
    time = 0
    x = mod_n[time]
    while(x % n != 0):
        time += 1
        if time == len(mod_n):
            time = 0
        ans += 1
        x += mod_n[time]
    print(ans)
    return 0

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
K = int(input())
n = len(str(K))

r = 7 % K
dict = defaultdict(bool)  # int/bool/list....
dict[r] = True
orgr = r
d = 1
for _ in range(K + 1):
    if r == 0:
        print(d)
        break
    d += 1
    r = (10 * r + 7) % K
    if dict[r]:
        print(-1)
        sys.exit()
    dict[r] = True

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


k = I()

m = k % 10
if m % 2 == 0 or m == 5:
    print(-1)
    exit()
if k == 1 or k == 7:
    print(1)
    exit()
else:
    rk = 7
    for i in range(2, 10 ** 6 + 1):
        rk1 = ((10 % k) * rk % k + 7 % k) % k
        if rk1 == 0:
            print(i)
            exit()
        rk = rk1

Submission status: Accepted

Solution code:

K = int(input())

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


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


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


K = z()
if K == 7:
    print(1)
    exit()

t = 7 % K
for i in range(1, K * 2):
    if t == 0:
        print(i)
        exit()

    t = (t * 10 + 7) % K

print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

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

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

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
K = int(input())

ans = 1
a = 7
i = K
while i > 0:
    m = a % K
    if m == 0:
        print(ans)
        break
    else:
        ans += 1
        a = m * 10 + 7
        i -= 1
if m != 0:
    print(-1)

Submission status: Accepted

Solution code:
K = int(input())

if K % 2 == 0:
  ans = -1
elif K % 5 == 0:
  ans = -1
else:
  ans = 1
  s = 7
  while s % K != 0:
    ans += 1
    s = str(s) + '7'
    s = int(s) % K
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():

    K = int(input())
    if 7 % K == 0: return 1
    r = 7 % K
    for i in range(2, 1000000):
        r = (r * 10 + 7) % K
        if r == 0:
            return i
    return -1




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

Submission status: Accepted

Solution code:
K = int(input())
dig1 = K%10
seven = 0
cnt = 1
if dig1 == 1 or dig1 == 3 or dig1 == 7 or dig1 == 9:
    for i in range(1, K+1):
        seven = seven * 10 + 7
        seven %= K
        if seven == 0:
            print(i)
            break
else:
    print(-1)

Submission status: Accepted

Solution code:
K = int(input())

t = 7
ans = 1

for _ in range(K):
    if t % K == 0:
        print(ans)
        exit(0)
    else:
        t = (t * 10 + 7) % K
        ans += 1

print(-1)

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np


mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*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)]

try:
    # sys.setrecursionlimit(int(pow(10,6)))
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("../output.txt", "w")
except:
    pass


# @lru_cache(None)




K=L()[0]
if K%2==0 or K%5==0:
    print(-1)
    exit()
i=1
s=7
while(s%K!=0 and i<10**8):
    s=(s*10+7)%K
    i+=1
print(i if i<10**8 else -1)

Submission status: Accepted

Solution code:
#import
#import math
#import numpy as np
K = int(input())

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

t = 7 % K
    
for i in range(1, K * 2):
    if t == 0:
        print(i)
        exit()

    t = (t * 10 + 7) % K

print(-1)

Submission status: Accepted

Solution code:
K = int(input())
ans = 1
now = 7
while now % K != 0:
   now = now * 10 + 7
   now = now % K
   ans += 1
   if ans == 10**6:
       break

if ans == 10**6:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
K = int(input())

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

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

print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections as cl
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()))


def main():
    k = II()

    amari = 0
    for i in range(k):
        amari = (amari * 10 + 7) % k
        if amari == 0:
            print(i + 1)
            return
    print(-1)


main()

Submission status: Accepted

Solution code:
from numba import njit

@njit
def solve(k):
    num = 0
    ans = -1
    for i in range(10 ** 7):
        num *= 10
        num += 7
        num %= k
        if num == 0:
            ans = i + 1
            break

    return ans


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

Submission status: Accepted

Solution code:
k = int(input())
i = int(str(k)[-1])
if(i % 2 == 0 | i % 5 == 0 ):
    print(-1)
else:
    num = 7
    result=1
    for i in range(k):
        if(num % k == 0):
            break
        else:
            num = (7+ num*10)%k
            result+=1
    else:
        result = -1
    print(result)

Submission status: Accepted

Solution code:
K = int(input())
f = 1
j = 7 % K
while f < K and j != 0:
    j = (j * 10 + 7) % K
    f += 1
if j == 0:
    print(f)
else:
    print('-1')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Problem C - Repsept
# input
K = int(input())

# initialization
seven = 7
ans = 1

# count
if K%2==0 or K%5==0:
    ans = -1
elif K==1:
    ans = 1
else:
    tmp_list = [0]*(10**6+1)
    while not seven%K==0: # 割り切れない限り
        seven = seven*10 + 7
        seven = seven % K
        ans += 1


# output
print(ans)

Submission status: Accepted

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

import sys

def main():
    k = int(input())
    sevens=0
    for i in range(1,k+1):
        sevens=(sevens*10+7)%k
        if sevens==0:
            print(i)
            exit()
    print(-1)

if __name__ == "__main__":
    main()