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 sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	k=II()
	a=0

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

	print(-1)





if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import sys

K = int(input())

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

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

count = 0
candidate = 1

while True:
    count += 1
    rem = candidate % K
    if rem == 0:
        print(count)
        sys.exit(0)
    candidate = 10*rem + 1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')

#solve
def solve():
    k = II()
    ans = 0
    for i in range(k + 1):
        ans += 7 * pow(10, i, k)
        ans %= k
        if ans:
            continue
        else:
            print(i + 1)
            return
    print(-1)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

K = int(input())
amari = []
s = 0
before = 0
for i in range(10 ** 6 + 1):
    if i == 0:
        s += 7 % K
        before = 7 % K
    else:
        before = before * 10 % K
        s += before
    s = s % K
    if s == 0:
        break
else:
    print("-1")
    sys.exit()

print(i + 1)






"""
7
77
777
7777

7
70 == 7 * 10 =
700 ==  



1
11
111
1111

k = 3
1 == 1
10 == 1
100 == 1

k = 4
1 == 1
10 == 2
100 == 0
100 == 10 * 10 == 2 * 10
"""

Submission status: Accepted

Solution code:
k = int(input())
cnt = 0

if k % 2 == 0:
	print(-1)
elif k % 5 == 0:
	print(-1)
else:
	val = 0
	keta = 7
	while True:
		if cnt == 0:
			keta = 7
		else:
			keta = (keta * 10) % k
		val = (val + keta) % k
		
		if val % k == 0:
			break
		else:
			cnt += 1
	print(cnt + 1)

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    K = int(input())
    S = [7] * K
    T = [0] * len(S)

    if K == 7 or K == 1:
        print(1)
        return
    
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return
    
    P = K
    T[0] = S[0] % P
    power = 1

    ans = -1
    for i in range(1, len(S)):
        power *= 10
        power %= P
        T[i] = T[i-1] + power * S[i]
        T[i] %= P

        if T[i] == 0:
            ans = i + 1
            break

    # print(T)
    # counter = Counter(T)
    # ans = sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import sys

def main():
    #an+1=(10~n)*7+an
    K=int(input())

    if K%2==0:
        print(-1)
        sys.exit()
    elif K%5==0:
        print(-1)
        sys.exit()
    n=0
    a=7
    while True:
        if a%K==0:
            break
        n+=1
        a=(a+(pow(10,n,K)*7))%K
    print(n+1)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import math
K = int(input())
if math.gcd(10, K) != 1:
    print(-1)
else:
    for i in range(1, 10**6+1):
        if 7*(pow(10, i, 9*K)-1) % (9*K) == 0:
            print(i)
            break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
k = int(input())
pre = 0
for i in range(1, k + 7):
    pre = (pre * 10 + 7) % k
    if pre == 0:
        print(i)
        exit()
print(-1)

Submission status: Accepted

Solution code:
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
k=N()
x=7%k
ans=1
for i in range(2*k):
    if x==0:
        print(ans)
        break
    x=x*10+7
    x%=k
    ans+=1
else:
    print(-1)

Submission status: Accepted

Solution code:
k=int(input())
flag=1
ans=1
r=7%k
p=r
if k%2==0:
    print(-1)
    exit()
if k%5==0:
    print(-1)
    exit()
while flag!=0:
    if r%k==0:
        flag=0
    else:
        ans+=1
        p=(p*10)%k
        r+=p
print(ans)

Submission status: Accepted

Solution code:
K = int(input())
mod = 7 % K
if mod == 0:
    print(1)
    quit()

s = set()
s.add(mod)
ans = 1
while mod != 0:
    mod = (mod*10 + 7) % K
    ans += 1
    if mod in s:
        print(-1)
        quit()
    s.add(mod)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

if(K in [1, 7]):
    print(1)
else:
    now = 7 % K
    a = 10 % K
    for n in range(2, 1000001):
        now = (now * a + 7) % K
        if(now == 0):
            print(n)
            break
    else:
        print(-1)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


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

Submission status: Accepted

Solution code:
K = int(input())

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

print(f(K))

Submission status: Accepted

Solution code:
k=int(input())

s=7
cnt=1
m=0

while(1):

  t=s%k
  if m==0 and t!=s:
    m=t
  elif m==t:
    print("-1")
    break

  if t==0:
    print(cnt)
    break
  else:
    s=t*10 + 7

  cnt+=1

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    K=ii()

    i = 1
    x = 7 % K
    if x == 0:
        print(1)
        exit()

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


    # i = 1
    # while True:
    #     x = (7**i) * K
    #     if x % 7 == 0:
    #         y = x // 7
    #         f = True
    #         for s in str(y):
    #             if s != "1":
    #                 f = False
    #                 break
            
    #         if f:
    #             print(len(str(y)))
    #             exit()
                
    #     i+=1


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

K = int(input())
base = 0
seen = set()

for i in range(10**6):
    base += 7 * pow(10, i, K)
    base %= K
    if base == 0:
        print(i+1)
        sys.exit()
    elif base in seen:
        print(-1)
        sys.exit()
    seen.add(base)

Submission status: Accepted

Solution code:
k = int(input())
p = -1
if((k%2)*(k%5) != 0):
    p = 1
    a = 7%k
    while(a > 0):
        a *= 10
        a += 7
        a %= k
        p += 1
print(p)

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    
    t = 0
    for i in range(10**6):
        t += (7*pow(10,i,k))
        t %= k
        if t==0:
            print(i+1)
            return

    print(-1)    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

print(-1)

Submission status: Accepted

Solution code:
import sys


def resolve(in_):
    k = int(next(in_))
    if not k % 2:
        return -1

    seven = 7 % k

    for i in range(1, 1000000):
        if not seven:
            return i
        i += 1
        seven = seven * 10 + 7
        if seven >= k:
            seven %= k

    return -1

def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n=int(input())
f=0
ans=7
if n%2==0:
    print(-1)
else:
    count=1
    while(ans<n):
        ans*=10
        ans+=7
        count+=1
    for i in range(count,10**6+1):
        ans=ans%n
        if ans==0:
            print(i)
            f=1
            break
        ans*=10
        ans+=7
    if f==0:
        print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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


now, cnt = 7, 1
while now % K != 0:
    cnt += 1
    now = now * 10 % K + 7

print(cnt)

Submission status: Accepted

Solution code:
k=int(input())
n='7'
cnt=1
if k%2==0 or k%5==0:
  print(-1)
  exit()
while True:
  if int(n)%k!=0:
    n=int(n)%k
    n=str(n)+'7'
    cnt+=1
  else:
    print(cnt)
    exit()

Submission status: Accepted

Solution code:
import datetime
import string
import re
import math

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

Submission status: Accepted

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

Submission status: Accepted

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

    tmp1 = 7 % K
    tmp2 = tmp1

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

    print(-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
i = 7
count = 1
judge = True
for t in range(10**6):
  if i%k == 0:
    judge = False
    break
  count += 1
  i = 10*(i%k)+7
if judge:
  print(-1)
else:
  print(count)

Submission status: Accepted

Solution code:
k = int(input())

flag = 0
count = len(str(k))

if k % 2 == 0:
  print(-1)
  exit()
  
if str(k)[-1] == '5':
  print(-1)
  exit()

count = len(str(k))
test = int('7' * count)
amari = test % k
while True:
  if amari == 0:
    break
  else:
    amari = (amari * 10 + 7) % k
    count += 1
  
print(count)

Submission status: Accepted

Solution code:
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
#import numpy as np
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s, n, node):
    # 頂点が探索済みかどうかのチェック配列
    check = [False for _ in range(n)]
    check[s] = True
    # 次見る頂点を格納するキュー
    queue = deque([s])
    visited_num = 1

    # 問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color = [-1 for _ in range(n)]
    color[s] = 0

    while visited_num < n:
        # グラフが全連結ではない場合
        if len(queue) == 0:
            # 空配列を返す
            # 現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex = queue.popleft()
        # インデックスがない場合は
        for next_vertex in node[now_vertex]:

            if check[next_vertex] == True:
                continue

            queue.append(next_vertex)
            check[next_vertex] = True

            # 問題固有の計算
            color[next_vertex] = color[now_vertex]+1
            visited_num += 1

    return color


mod = 10**9+7
# n=int(input())
# n,m=list(map(int,input().split()))
# a=list(map(int,input().split()))
def ceil(x, y): return (x+y-1)//y
def input_list(): return list(map(int, input().split()))


n = int(input())
num = 10**6
cal = [(7*pow(10, i, n)) % n for i in range(num)]
# print(cal[:10])
# n, m = list(map(int, input().split()))
c = 0
for i in range(num):
    c += cal[i]
    c %= n
    if c == 0:
        print(i+1)
        exit()

print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

a = 7
p = {}
ans = 0

while True:
    t = a % K
    ans += 1
    if t == 0:
        print(ans)
        break
    if t in p:
        print(-1)
        break
    a = 10*t + 7
    p[t] = 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
import sys
i = 1
amari = 7%k
ama = 7%k
while True:
    if amari%k ==0:
        print(i)
        sys.exit()
    else:
        ama = (ama*10)%k
        amari += ama
        i +=1
    if i == k+1:
        break
print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

k=int(input())
if k%2==0 or k%5==0:
    print(-1)
    exit()
r=7%k
for i in range(1,10**7):
    if r==0:
        print(i)
        exit()
    r+=(7*pow(10,i,k))
    r%=k
print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(k):
    if(k%2==0 or k%5==0):
        return -1
    if(k%7==0):
        k//=7
    amari=1
    now=1
    for i in range(k+1):
        if(now%k==0):
            return i+1
        amari*=10
        amari%=k
        now+=amari
        now%=k
    return -1

k=int(input())

print(solve(k))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

k = inp()
if k%2 == 0 or k%5 == 0:
    print(-1)
    quit()
now = 0
for i in range(k+10000):
    now += pow(10,i+1,k)*7
    # print(now)
    now %= k
    if now == 0:
        print(i+1)
        quit()
print(-1)

Submission status: Accepted

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

Submission status: Accepted

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


now=0
count=0
N=0
flag=False
while True:
    now+=(7*pow(10,count, K))%K
    now%=K
    #print(N)
    if not flag:
        N+=7*10**(count)
    if N>=K:
        flag=True
    #print(now, count)
    if now==0 and flag:
        print(count+1)
        exit()
    count+=1
    if count>10**6:
        break


print(-1)

Submission status: Accepted

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

table = [0] * k
a = math.floor(math.log10(k))

num = 7
base = 1
result = 1
for i in range(a):
  base *= 10
  result += 1
  num += base * 7
if(num < k):
  base *= 10
  result += 1
  num += base * 7

div = (num - k) % k

while(div != 0 and table[div]==0):
  table[div] = 1
  div = (div * 10 + 7) % k
  result += 1

if(div == 0):
  print(result)
else:
  print(-1)

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    ans = 0
    prev = 0
    seen = set()
    tenmod = 10 % K
    sevenmod = 7 % K
    for  i in range(K):
        m = ((tenmod * prev) + sevenmod ) % K
        if m == 0:
            print(i+1)
            break
        if m in seen:
            print(-1)
            break
        seen.add(m)
        prev = m
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
Ali = []

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

Submission status: Accepted

Solution code:
k=int(input())
a="0"
l=[]
if k%2==0:
  print("-1")
else:
  for i in range(k):
    a=a+"7"
    b=int(a)
    b=b%k
    if b==0:
      ans=i+1
      l.append(ans)
      print(ans)
      break
    a=str(b)
  if l==[]:
    print("-1")

Submission status: Accepted

Solution code:
import sys
k=int(input())
A=[0]*k
C=[7%k]
A[7%k]=1
if 7%k==0:
    print(1)
    sys.exit()
while True:
    now=(C[-1]*10+7)%k
    if A[now]==1:
        print(-1)
        break
    A[now]=1
    C.append(now)
    if now==0:
        print(len(C))
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import time
K=int(input())
mod=7%K

if 7%K==0:
  print(1)
  exit()
ans=1
now=time.time()
while 1:
  ans+=1
  mod=(mod*10+7)%K
  if mod==0:
    print(ans)
    break
  if time.time()-now>=1.8:
    print(-1)
    break

Submission status: Accepted

Solution code:
k=int(input())

d=7%k
c=-1
for i in range(10**6+10):
    if d==0:
        c=i+1
        break
    d=(d*10+7)%k

    
print(c)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

K = int(input())

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

Submission status: Accepted

Solution code:
k = int(input())

a = 7
counter = 1
flag = 0

for i in range(k):
    r = a%k
    if(r == 0):
        print(counter)
        flag = 1
        break
    else:
        counter += 1
        a = 10*r + 7%k

if(flag == 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(0)

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

Submission status: Accepted

Solution code:
n=int(input())

sm=0
work=7
for i in range(1,5*n):
    sm+=work
    while sm>=n:
        sm-=n
    if sm==0 :
        print(i)
        break
    work*=10
    work%=n
else : print(-1)

Submission status: Accepted

Solution code:
K = int(input())

def main(K):
  cnt = 1
  amari = 0
  while True:
    amari *= 10
    amari += 7
    amari %= K
    if amari == 0:
      return cnt
    else:
      cnt += 1
  

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

Submission status: Accepted

Solution code:
#create date: 2020-08-02 21:08

import sys
stdin = sys.stdin

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

def divisor(n):
    i = 1
    table = [7, ]
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(7*i)
            table.append(n // i)
            table.append((n//i)*7)
        i += 1
    table = set(table)
    return table


def main():
    k = ni()
    a = 0
    for i in range(1, 10**6+1):
        a = (10*a + 7) % k
        if a == 0:
            print(i)
            quit()
    print(-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    #t=int(input())
    t=1
    for _ in range(t):
        n=int(input())
        num=7
        ans=0
        ls={}
        while 1:
            if num%n==0:
                ans+=1
                break
            else:
                if num%n in ls:
                    ans=-1
                    break
                ls[num%n]=1
                st=num%n
                st=str(st)+"7"
                #print(st)
                ans+=1
                num=int(st)
        print(ans)






BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

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

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

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

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


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


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

if __name__ == "__main__":
    main()
    #threadin.Thread(target=main).start()

Submission status: Accepted

Solution code:
k = int(input())

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

sevens = 7
for i in range(1000000):
	if sevens % k == 0:
		print(str(i+1))
		quit()
	else :
		sevens = (sevens % k) * 10 + 7

print(-1)
quit()

Submission status: Accepted

Solution code:
K = int(input())
count = 1
rem = 7 % K

if K % 2 == 0:
    print(-1)
elif rem % K == 0:
    print(1)
else:
    while (rem % K) != 0 and count <= K:
        count += 1
        rem += 7 * pow(10, count-1, mod=K) % K
    if count <= K:
        print(count)
    else:
        print(-1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
K = int(input())
if K % 3 == 0: K *= 9
for x in range(1, K + 1):
  if 7 * (pow(10, x, K) - 1) % K == 0:
    print(x)
    break
else: print(-1)

Submission status: Accepted

Solution code:
K = int(input())

his = set()
cnt = 0
x = 7
while True:
    cnt += 1
    r = (x % K)
    if r == 0:
        print(cnt)
        break
    if r in his:
        print(-1)
        break
    his.add(r)
    x = r * 10 + 7
exit()

Submission status: Accepted

Solution code:
num = int(input())
val = 7
cnt = 1
while True:
    val %= num
    if cnt >= 10 ** 6: 
        cnt = -1
        break
    if val == 0: break
    val *= 10
    val += 7
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
K = int(input())
amari = 0
res = set()
tmp = 7
flag = False
for i in range(10**6):
    if i == 0:
        if tmp % K == 0:
            flag = True
        else:
            tmp = tmp % K
            res.add(tmp)
            amari += tmp
    else:
        tmp = (tmp * 10) % K
        amari += tmp
        amari = amari % K
        if amari == 0:
            flag = True
    if flag:
        break
if flag:
    print(i + 1)
else:
    print(-1)

Submission status: Accepted

Solution code:
k=int(input())
if k%2==0 or k%5==0:
  print(-1)
  exit()
  
le=len(str(k))
p=int(''.join(['7']*le))
i=0
s=p%k
while True:
  if s==0:
    print(le+i)
    exit()
  else:
    s+=7*pow(10,le+i,k)
    s%=k
    i+=1

Submission status: Accepted

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