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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

K = INT()

checked = [0]*K
a = 0
for i in range(K):
	a = (a+7*pow(10, i, K))%K
	if a == 0:
		print(i+1)
		break
	if checked[a]:
		print(-1)
		break
	checked[a] = 1

Submission status: Accepted

Solution code:
k = int(input())

num = 7
cnt = 1
for i in range(k):
    if num % k == 0:
        break

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

if num % k == 0:
    print(cnt)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

go = 0
keta = len(str(k))

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

Submission status: Accepted

Solution code:
K = int(input())

nana = 7
count = 1

mod = 7 % K 

past = {mod}

while mod != 0:
  mod = (mod * 10 + 7) % K
  if mod in past:
    break
  past.add(mod)
  count += 1
  
if mod == 0:
  print(count)
else:
  print(-1)

Submission status: Accepted

Solution code:
K=int(input())

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

mod=1
ans=-1
for i in range(1,L+1):
    mod=(mod*10)%L
    if mod%L==1:
        ans=i
        break

print(ans)

Submission status: Accepted

Solution code:
k = int(input())

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

print(f(k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    k = int(input())
    ans = 1

    if k % 2 == 0 or k % 5 == 0:
        print(-1)
    else:
        a = 7
        while 1:
            if a % k == 0:
                print(ans)
                break
            else:
                a = (a % k) * 10 + 7
                ans += 1
if __name__ == '__main__':
    main()

Submission status: Accepted

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

K = INT()

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

Submission status: Accepted

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

Submission status: Accepted

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

  # K が偶数だったら存在しない
  if K % 2 == 0 or K % 5 == 0:
    print(-1)
    return True

  L = 9 * K
  if K % 7 == 0:
    L = int(K / 7 * 9)

  target = 10
  for i in range(1, L+1):
    mod_L = target % L
    # print(mod_L)
    if mod_L == 1:
      print(i)
      return True
    target = mod_L*10

  print(-1)

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
k = int(input())
if k % 2 == 0:
    print(-1)
elif k % 5 == 0:
    print(-1)
else:
    c = 7
    count = 1
    while True:
        if c % k == 0:
            print(count)
            break
        else:
            c = (10 * c + 7) % k
            count += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K=int(input())
if K%2==0:
    print(-1)
else:
    if K%7==0:
        L=9*K//7
    else:
        L=9*K
    rest=10%L
    for i in range(1,L+1):
        if rest==1:
            print(i)
            exit()
        else:
            rest=(rest*10)%L
        if i==L and rest!=1:
            print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
K = int(s)

if ((K & 1 == 0) or (s[-1] == "5")):
  print(-1)
else:
  if K % 7 == 0:
    L = 9 * K / 7
  else:
    L = 9 * K

  i = 1
  r = 10
  while True:
    r = r % L
    if r == 1:
      print(i)
      break
    r *= 10
    i += 1

Submission status: Accepted

Solution code:
import sys

k=int(input())
if k%2==0:
  print(-1)
  sys.exit(0)
c=1
m=7%k
while 1:
  if m==0:
    print(c)
    sys.exit(0)
  if c>k+1:
    print(-1)
    sys.exit(0)
  m=m*10+7
  m%=k
  c+=1

Submission status: Accepted

Solution code:
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

K = INT()

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

Submission status: Accepted

Solution code:
#正答
k=int(input())
a=set()
count=1
if k%2==0:
    print(-1)
else:
    #下の桁に７を足していく
    ai=7%k
    while 1:
        if ai==0:
            print(count)
            break
        elif ai in a:
            print(-1)
            break
        else:
            a.add(ai)
            ai=(ai*10+7)%k
            count+=1

Submission status: Accepted

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

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

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

    x = 7
    first = True
    flag = False
    for i in range(1000000):
        if(first):
            x = 7
            first = False
        else:
            #x = (x * 10) + 7
            x = (x * 10)%K + 7%K
        
        if(x % K == 0):
            print(i+1)
            flag = True
            break
    
    if(flag != True):
        print(-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())

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

print(func(K))

Submission status: Accepted

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

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 = (10 * a + 7) % k
print(-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# template: v1.3.1

# 倍数問題では、N(i)%k は k 以内でループする...はず。実際している…
# 桁落としは、mod 途中実行でできる…了解...！！！！！合点！！！！

import io
import sys
import math

### DEBUG ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
999983
"""
_EXPECTED = """\
4

"""
if _DEB:
    sys.stdin = io.StringIO(_INPUT)
    print("!! Debug Mode !!")

def logd(str):
    if _DEB: print(f"[deb] {str}")


### INPUT ####
k = int(input())

### Solve ####
def solve():
    # Process
    ans=-1
    mod_set=set()
    modx=10**9+7
    i=1
    n7=7%k
    while True:
        if n7==0:
            ans=i
            break
        if n7 in mod_set:
            break
        mod_set.add(n7)
        # 7777... の連続生成は、こうすると合理的。桁あふれもここで防ぐ。
        n7=(n7*10+7)%k
        i+=1
    # OUPUT
    ans = str(ans)
    print(ans)
    return ans

### MAIN ###
if __name__ == "__main__":
    ans = solve()

    # Checker
    if _DEB:
        if _EXPECTED.strip() == ans.strip(): print("\n!! Success !!")
        else: print(f"\n!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Submission status: Accepted

Solution code:
k = int(input())

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

    return -1

print(solve())

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

ans = 1
num = 10
while True:
    if num % l == 1:
        break
    num = (num % l) * 10
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
k=int(input())
d = 0
for i in range(k+1):
  d = (10*d) + 7
  d %= k #割り算して、余りをdに代入
  if d == 0:
    print(i+1)
    sys.exit()

print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict 
import sys
import math 

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n = int(input())

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

Submission status: Accepted

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

def main():
    K = int(input())
    if K % 7 == 0:
        L = 9 * K / 7
    else:
        L = 9 * K
    if L % 2 == 0 or L % 5 == 0:
        ans = -1
    else:
        i = 1
        tmp = 10
        while True:
            tmp %= L
            if tmp == 1:
                ans = i
                break
            i += 1
            tmp *= 10

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 in [0, 2, 4, 5, 6, 8]:
        print(-1)
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            elif tmp // 10 % 10 == 8:
                num = 9
            elif tmp // 10 % 10 == 9:
                num = 8
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
k = int(input())

i = 0
mod = 0
while True:
    mod = (mod*10 + 7) % k
    if mod == 0:
        break
    i += 1
    if i == k:
        i = -2
        break
 
print(i+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())
v=[1]*k
if k==1 or k==7:
  print(1)
  exit()
m=7%k
v[m]=0
for i in range(k):
  m=(10*m+7)%k
  if m==0:
    c=i+2
    break
  elif v[m]:
    v[m]=0
  else:
    c=-1
    break
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 == 2 or k % 10 == 4 or k % 10 == 5 or k % 10 == 6 or k % 10 == 8 or k % 10 == 0:
        print(-1)
        exit()
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            elif tmp // 10 % 10 == 8:
                num = 9
            elif tmp // 10 % 10 == 9:
                num = 8
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > k:
                print(-1)
                break

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 == 2 or k % 10 == 4 or k % 10 == 5 or k % 10 == 6 or k % 10 == 8 or k % 10 == 0:
        print(-1)
        exit()
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            elif tmp // 10 % 10 == 8:
                num = 9
            elif tmp // 10 % 10 == 9:
                num = 8
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 5 * 10 ** 7:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    Kstr = str(K)
    
    if Kstr[-1] in ('0','2','4','6','8','5'):
        print(-1)
    else:
        if K%7 == 0:
            L = (9*K)/7
        else:
            L = 9*K
        S = 10
        for i in range(1,100000000000):
            S = S%L
            if S == 1:
                print(i)
                break
            S = S*10
    
if __name__ == '__main__':
    main()
    
#def test():
#    K = int(input())
#    S = 7
#    
#    for K in range(1,200):
#        S = 7
#        for i in range(1,200):
#            if S % K == 0:
#                print(str(K)+' '+str(i))
#                break
#            S = S*10 + 7

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    Kstr = str(K)
    
    if Kstr[-1] in ('0','2','4','6','8','5'):
        print(-1)
    else:
        if K%7 == 0:
            L = (9*K)/7
        else:
            L = 9*K
        S = 10
        for i in range(1,6000000):
            S = S%L
            if S == 1:
                print(i)
                break
            S = S*10
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
k = int(input())


i = 0;
mod = 0;
while True:
    mod = (mod*10 + 7) % k;
    if mod == 0:
        break;
    i += 1;
    if i == k:
        i = -2
        break;

print(i+1)

Submission status: Accepted

Solution code:
k = int(input())

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

val = 7
idx = 1

while True:
    if val % k == 0:
        break
    else:
        idx += 1
        val = (val * 10 + 7) % k

print(idx)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    k = int(input())

    if k % 2 == 0 or k % 5 == 0:
        print('-1')
    else:
        mod_list = [7 % k]
        if mod_list[-1] == 0:
            print(1)
        else:
            for i in range(1000000):
                mod_list.append((mod_list[0] + mod_list[-1] * 10) % k)
                if mod_list[-1] == 0:
                    break
            print(len(mod_list))

Submission status: Accepted

Solution code:
K = int(input())
a = ""
ans = 0
amari = 10

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

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

    for p in range(10**6):
        if amari % L == 1:
            print(p+1)
            break
        else:
            amari = (amari*10)%L

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    k = ni()

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

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

r = 7 % k
ans = 1
cnt = [0] * (k+1)
while r != 0:
  cnt[r] = 1
  r *= 10
  r += 7
  r %= k
  ans += 1
  if cnt[r]:
    ans = -1
    break

print(ans)

Submission status: Accepted

Solution code:
k = int(input())

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

else:
    if k % 7 == 0:
        d = (9 * k) // 7
    else:
        d = 9 * k
    
    res = 10

    for i in range(1, 100000000):
        if res % d == 1:
            print(i)
            exit()
        else:
            res = (res % d) * 10
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math
import bisect

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()


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

print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
k = int(sys.stdin.read())
if k==2:
  print(-1)
  sys.exit()
value = 0
index = 0
while index < 1000000:
  index += 1
  value = (value*10+7)%k
  if value == 0:
    print(index)
    sys.exit()

print(-1)

Submission status: Accepted

Solution code:
k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    i = 1
    m = 7 % k
    while True:
        if m == 0:
            print(i)
            break
        m = (10 * m + 7) % k
        i += 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

K = INT()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
x = 7
ans = 1
flag = [False]*k
while x%k != 0:
    ans += 1
    x = (x*10%k+7)%k
    if flag[x]:
        ans = -1
        break
    flag[x] = True
print(ans)

Submission status: Accepted

Solution code:
# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase
def main():
    k = int(input())
    ans=val=7%k
    fin,n = -1,1
    se = set()
    while ans not in se:
        if not ans:
            fin = n
            break
        se.add(ans)
        val *= 10
        val %= k
        ans += val
        ans %= k
        n += 1
    print(fin)

# Fast IO 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")
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:
k = int(input())
a=7
i=1
if k%5==0 or k%2==0:
  print(-1)
  exit()
while True:
  if a%k ==0:
    print(i)
    break
  i+=1
  a=(a*10+7)%k

Submission status: Accepted

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

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

s = 1
for i in range(1,K+1):
    if s % K == 0:
        print(i)
        exit()
    else:
        s *= 10
        s += 1
        s %= 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()

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
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)