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:
N=int(input())
a=0
ans=1
num=0
if N%2==0 or N%5==0:
   print(-1)
   exit()
while True:
   num=(num*10+7)%N
   if num==0:
      print(ans)
      exit()
   ans+=1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

k = r()
val = 7%k
ans = False
for i in range(1,10**6+1):
    if val==0:
        ans = True
        print(i)
        break
    val = (val*10+7)%k
if not ans:
    print(-1)

Submission status: Accepted

Solution code:
n = int(input())
x, found = 0, False
for i in range(1, n + 1):
  x = ((10 * x) + 7)%n
  if x == 0:
    print(i)
    found = True
    break

if not found:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

def seven():
    seven_i = 0
    count = 0
    for i in range(K):
        seven_i = ((10*seven_i) + 7) % K
        count += 1
        if seven_i % K == 0:
            return count
    return -1

print(seven())

Submission status: Accepted

Solution code:
## coding: UTF-8

K = int(input())

tmp = 0
stat = True
for i in range(1, K+10):
    tmp *= 10
    tmp %= K
    tmp += 7
    tmp %= K
    #print(i, tmp)
    if(tmp == 0):
        print(i)
        stat = False
        break

if(stat):
    print(-1)



'''
seven = []
tmp = 0
for i in range(10**4+10):
    tmp *= 10
    tmp += 7
    seven.append(tmp)


#OK = []
#kasetu = []
#for K in range(1):


#K = 999983
#tmp = 0

for K in range(1, 200):
    for j in range(10**4 + 10):
        #tmp *= 10
        #tmp += 7
        if(seven[j] % K == 0):
        #if(tmp % K == 0):
            print('K:{}, j+1:{}, seven[j]/K:{}'.format(K, j+1, seven[j]/K))
            #print('K:{}, j+1:{}, tmp:{}'.format(K, j+1, tmp))
            #OK.append(K)
            break
        #if( K % 2 != 0 and K % 5 != 0):
            #kasetu.append(K)

#print(OK)
#print(kasetu)
#print(OK == kasetu)
'''

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
K = int(input())

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

if L % 2 == 0 or L % 5 == 0:
    print(-1)
else:
    rest = 1
    ans = 0
    while True:
        rest *= 10
        ans += 1
        rest = rest % L
        if rest == 1:
            break
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
val = 7
visited = set()
counter = 1
while len(visited) < k:
    val %= k
    if val in visited:
        print(-1)
        break
    elif val % k == 0:
        print(counter)
        break
    else:
        visited.add(val)
        val = (val * 10 + 7) % k
        counter += 1

Submission status: Accepted

Solution code:
k = int(input())
seen = set()
num = 7
while True:
  if num%k==0:
    print(len(seen)+1)
    exit()
  elif num%k in seen:
    print("-1")
    exit()
  else:
    seen.add(num%k)
    num = (num*10+7)%k

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    if K%2 == 0:
        return -1
    ans = 1
    amari_reserve = 7%K
    amari = amari_reserve
    if amari_reserve == 0:
        return ans

    while (ans <= K):
        ans += 1
        amari = (10*amari+7) % K
        if amari == 0:
            return ans
        if amari == amari_reserve:
            return -1

    return -1


print(main())

Submission status: Accepted

Solution code:
k = int(input())
j = 7

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


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


sys.setrecursionlimit(20000000)

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


def check(n):
    C = ["0", "1", "2", "3", "4", "5", "6", "8", "9"]
    for c in C:
        if c in str(n):
            return False
    return True


def main():
    K = int(input())
    if K % 2 == 0:
        print(-1)
        return
    if K % 5 == 0:
        print(-1)
        return
    if K % 7 == 0:
        L = 9 * K // 7
    else:
        L = 9 * K
    cnt = 1
    amari = 10 % L
    while True:
        if amari == 1:
            print(cnt)
            return
        amari = amari * 10 % L
        cnt += 1


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())

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

    mod = (10*mod + 7) % K

if mod == 0:
    print(K)
else:
    print(-1)

Submission status: Accepted

Solution code:
N = int(input())

# if N < 7:
#     print(-1)
#     exit()
if N % 2 == 0 or N % 5 == 0:
    print(-1)
    exit()
i = 0
num = 0
while True:
    num = (num * 10 + 7) % N
    i += 1
    if num == 0:
        print(i)
        exit()

K = int(input())

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

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

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    x = 0
    flag = True
    # 等比数列の和
    # 初項7 公比10 
    # 7 * (1-10**i) / (1-10)
    # 7*(10**i-1)/9
    # これをkで割りきれるか
    # 7*(10**i-1) を 9*kで我りきれるか
    # kが7倍数かそうでないかで条件分ける
    # 割った余りを保持しておいて10倍してまた割るを繰り返す
    mod = 1
    for i in range(1, 10**6+1):
        mod *= 10
        if k % 7 == 0:
            mod = mod % (9*k/7)
            if mod == 1:
                print(i)
                flag = False
                break
        else:
            mod = mod % (9*k)
            if mod == 1:
                print(i)
                flag = False
                break

    if flag:
        print('-1')
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def f(K):
    sum = 0
    p10 = 1
    for i in range(K+1):
        sum += p10*7
        p10 *= 10
        p10 %= K
        sum %= K

        if sum == 0:
            return i+1
    return -1


K = int(input())

print(f(K))

Submission status: Accepted

Solution code:
def f(K):
    sum = 0
    for i in range(K+1):
        sum += (pow(10, i, K)*7)
        sum %= K

        if sum == 0:
            return i+1
    return -1


K = int(input())

print(f(K))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(a, b):
  if a < b:
    return gcd(b, a)
  if b == 0:
    return a
  return gcd(b, a%b)

K = int(input())

if gcd(K, 10) != 1:
  print(-1)
else:
  if K % 7 == 0:
    K//=7
  ans = 1
  cur = 1
  while cur % K != 0:
    cur += pow(10, ans, K)
    ans += 1
  print(ans)

Submission status: Accepted

Solution code:
def solve():
	n = int(input())
	if n%2 == 0 or n%5 == 0:
		return -1
	if n % 7 == 0:
		n//=7
	n*=9
	cnt = 1
	cur = 10
	while cur % n != 1:
		cur = (cur * 10)%n
		cnt+=1
	return cnt




print(solve())

Submission status: Accepted

Solution code:
K = int(input())
if K == 7 or K == 1:
    print(1)
else:
    if K % 7 == 0:
        K //= 7
    r = 1
    for i in range(1,K+1):
        if r == 0:
            print(i)
            break
        r += pow(10,i,K)
        #print(r)
        r %= K
    else:
        print(-1)

Submission status: Accepted

Solution code:
import math

k = int(input())

count = 0
value = 0
remain_sum = 7
digit_remain = 7

while True:
    if count > k:
        print(-1)
        break
    if remain_sum % k == 0:
        print(count+1)
        break
    digit_remain = digit_remain * 10 % k
    remain_sum += digit_remain

    count += 1

Submission status: Accepted

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

rem = 7%K

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

Submission status: Accepted

Solution code:
k=int(input())

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

num=7
num%=k
ans=1

while num!=0:
  num=10*num+7
  num%=k
  ans+=1

print(ans)

Submission status: Accepted

Solution code:
#abc174_c

k=int(input())

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

Submission status: Accepted

Solution code:
#abc174_c

k=int(input())

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

Submission status: Accepted

Solution code:
#abc174_c

k=int(input())

# kの倍数が登場 -> 77...777%k==0となる最小の77の長さは？
if k%2==0:
    print(-1)
    exit()
if k==1:
    print(1)
    exit()
if k==7:
    print(1)
    exit()

rem=7%k
for i in range(2,k+1):
    rem=(rem*10+7)%k
    if rem==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()

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

ans=1
q=10%l

while q!=1:
  q*=10
  q%=l
  ans+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K=int(input())
num=7
count = 0
checkK = [0 for j in range(K)]
result = ""

flag = True
while(flag):
    count += 1
    if num%K==0:
        flag = False
        result = str(count)
    num = (num*10+7)%K
    checkK[num] += 1
    if checkK[num] == 2:
        flag = False
        result = "-1"
print(result)

Submission status: Accepted

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

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


K = int(input())

# 解法1
# 数列 s は、s[1] = 7, s[i+1] = s[i] * 10 + 7 の漸化式で与えられる
# 特性方程式 α = α * 10 + 7 を考えると、α = -7/9 より、
# s[i+1] + 7/9 = 10 * (s[i] + 7/9) となる
# つまり、s[i] + 7/9 = 10^(i-1) * (7 + 7/9)
# <=> s[i] = 10^(i-1) * 70/9 - 7/9
# <=> s[i] = 7/9 * (10^i - 1)
# よって、7/9 * (10^i - 1) % K == 0 となるような最小の正の整数 i を求めれば良いことになる
# K と 10 が互いに素でない場合は答えが存在しないことに注意

# 解法2
# s[i] = s[i-1] * 10 + 7 より、s[i] % K = (s[i-1] * 10 + 7) % K (ただし、s[0] = 0)
# <=> s[i] % K = s[i-1] * 10 % K + 7 % K
# K と 10 が互いに素でない場合は答えが存在しないことに注意

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
mod = 7 % k
ans = -1

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

print(ans)

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

k = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
k=int(input())
if k%7==0:k//=7
if math.gcd(10,k)!=1: exit(print(-1))
if k==1: exit(print(1))
v=1
ans=0
while(v!=0):
    v=(v*10+1)%k
    ans+=1 
print(ans+1)

Submission status: Accepted

Solution code:
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################

#check = [int(("1"*i))*7 for i in range(10**6 + 2)]
#print(check)
n = int(input())
temp = 7
for i in range(1,10**7):
	#print(temp)
	if temp%n == 0:
		print(i)
		exit()
	else:
		temp = ((temp*10) + 7)%n
print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
if k % 10 in [0, 2, 4, 5, 6, 8]:
  print("-1")
else:
  c = 1
  r = 7 % k
  while True:
    if r == 0:
      break
    else:
      c += 1
      r = (10*r+7) % k
  print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Hey, there Stalker!!!
# This Code was written by:
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
# ▒▒╔╗╔═══╦═══╗▒▒▒╔╗▒▒▒
# ▒╔╝║║╔═╗║╔═╗╠╗▒▒║║▒▒▒
# ▒╚╗║║║║║║║║║╠╬══╣║╔╗▒
# ▒▒║║║║║║║║║║╠╣║═╣╚╝╝▒
# ▒╔╝╚╣╚═╝║╚═╝║║║═╣╔╗╗▒
# ▒╚══╩═══╩═══╣╠══╩╝╚╝▒
# ▒▒▒▒▒▒▒▒▒▒▒╔╝║▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒╚═╝▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
#from functools import reduce

#mod=int(1e9+7)
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.stack_size(2**26)
"""fact=[1]
#for i in range(1,100001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*100001
#ifact[100000]=pow(fact[100000],mod-2,mod)
#for i in range(100000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod"""
#from collections import deque, defaultdict, Counter, OrderedDict
#from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
#from heapq import heappush, heappop, heapify, nlargest, nsmallest


# sys.setrecursionlimit(10**6) 
from sys import stdin, stdout
import bisect            #c++ upperbound
from bisect import bisect_left as bl              #c++ lowerbound bl(array,element)
from bisect import bisect_right as br             #c++ upperbound
import itertools
from collections import Counter

import collections
import math
import heapq
import re
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           #takes array as input
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
  
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l

def most_frequent(list):
    return max(set(list), key = list.count) 
def GCD(x,y):
    while(y):
        x, y = y, x % y
    return x

def ncr(n,r,p):                                              #To use this, Uncomment 19-25 
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t

def Convert(string): 
    li = list(string.split("")) 
    return li 

def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
prime=[]
q=[]
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j

#Implement heapq
#grades = [110, 25, 38, 49, 20, 95, 33, 87, 80, 90] 
#print(heapq.nlargest(3, grades)) #top 3 largest
#print(heapq.nsmallest(4, grades))
#Always make a variable of predefined function for  ex- fn=len
#n,k=map(int,input().split())
"""*******************************************************"""
def main():
        n=inin()
        cnt=1
        temp=0
        z=0
        flag=0
        while cnt<=n:
            #print(cnt,int(cnt*str(7))) 
            z=(10*z+7)%n
            if z==0:
                print(cnt)
                flag=1
                break
            cnt+=1
        if flag==0:
            print(-1)


"""*******************************************************"""
######## Python 2 and 3 footer by Pajenegod and c1729
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
 
import os, sys
from io import IOBase, BytesIO
 
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
if __name__== "__main__":
    main()
#threading.Thread(target=main).start()

Submission status: Accepted

Solution code:
# Hey, there Stalker!!!
# This Code was written by:
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
# ▒▒╔╗╔═══╦═══╗▒▒▒╔╗▒▒▒
# ▒╔╝║║╔═╗║╔═╗╠╗▒▒║║▒▒▒
# ▒╚╗║║║║║║║║║╠╬══╣║╔╗▒
# ▒▒║║║║║║║║║║╠╣║═╣╚╝╝▒
# ▒╔╝╚╣╚═╝║╚═╝║║║═╣╔╗╗▒
# ▒╚══╩═══╩═══╣╠══╩╝╚╝▒
# ▒▒▒▒▒▒▒▒▒▒▒╔╝║▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒╚═╝▒▒▒▒▒▒▒
# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
#from functools import reduce

#mod=int(1e9+7)
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.stack_size(2**26)
"""fact=[1]
#for i in range(1,100001):
#    fact.append((fact[-1]*i)%mod)
#ifact=[0]*100001
#ifact[100000]=pow(fact[100000],mod-2,mod)
#for i in range(100000,0,-1):
#    ifact[i-1]=(i*ifact[i])%mod"""
#from collections import deque, defaultdict, Counter, OrderedDict
#from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
#from heapq import heappush, heappop, heapify, nlargest, nsmallest


# sys.setrecursionlimit(10**6) 
from sys import stdin, stdout
import bisect            #c++ upperbound
from bisect import bisect_left as bl              #c++ lowerbound bl(array,element)
from bisect import bisect_right as br             #c++ upperbound
import itertools
from collections import Counter

import collections
import math
import heapq
import re
def modinv(n,p):
    return pow(n,p-2,p)
def cin():
    return map(int,sin().split())
def ain():                           #takes array as input
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
  
def Divisors(n) : 
    l = []  
    for i in range(1, int(math.sqrt(n) + 1)) :
        if (n % i == 0) : 
            if (n // i == i) : 
                l.append(i) 
            else : 
                l.append(i)
                l.append(n//i)
    return l

def most_frequent(list):
    return max(set(list), key = list.count) 
def GCD(x,y):
    while(y):
        x, y = y, x % y
    return x

def ncr(n,r,p):                                              #To use this, Uncomment 19-25 
    t=((fact[n])*((ifact[r]*ifact[n-r])%p))%p
    return t

def Convert(string): 
    li = list(string.split("")) 
    return li 

def SieveOfEratosthenes(n): 
    global prime
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    f=[]
    for p in range(2, n): 
        if prime[p]: 
            f.append(p)
    return f
prime=[]
q=[]
def dfs(n,d,v,c):
    global q
    v[n]=1
    x=d[n]
    q.append(n)
    j=c
    for i in x:
        if i not in v:
            f=dfs(i,d,v,c+1)
            j=max(j,f)
            # print(f)
    return j

#Implement heapq
#grades = [110, 25, 38, 49, 20, 95, 33, 87, 80, 90] 
#print(heapq.nlargest(3, grades)) #top 3 largest
#print(heapq.nsmallest(4, grades))
#Always make a variable of predefined function for  ex- fn=len
#n,k=map(int,input().split())
"""*******************************************************"""
def main():
    n=inin()
    if n&1==0:
        print(-1)
    else:
        cnt=1
        temp=0
        z=0
        flag=0
        while cnt<=n:
            #print(cnt,int(cnt*str(7))) 
            z=(10*z+7)%n
            if z==0:
                print(cnt)
                flag=1
                break
            cnt+=1
        if flag==0:
            print(-1)


"""*******************************************************"""
######## Python 2 and 3 footer by Pajenegod and c1729
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
 
import os, sys
from io import IOBase, BytesIO
 
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
 
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None
 
    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
 
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()
 
    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
if __name__== "__main__":
    main()
#threading.Thread(target=main).start()

Submission status: Accepted

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

    is_not_found = True
    memo = [0 for _ in range(K)]

    i=7%K
    res = 1
    if i == 0:
        is_not_found = False

    while is_not_found and memo[i] == 0:
        memo[i] += 1
        if i == 0:
            is_not_found = False
        else:
            res += 1
            i = (i * 10 + 7) % K

    print(res) if is_not_found == False else print(-1)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

L = 9 * K

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

power = 1

for i in range(1, 10 ** 6):
    power *= 10
    power %= L
    if power == 1:
        print(i)
        sys.exit()

print(-1)

Submission status: Accepted

Solution code:
k = int(input())
if k % 7 == 0:
    L = 9 * k / 7
else:
    L = 9 * k
 
if L % 2 == 0 or L % 5 == 0:
    print(-1)

m = 10

for i in range(k):
    m = m % L
    if m == 1:
        print(i + 1)
        exit()
    else:
        m = m * 10

Submission status: Accepted

Solution code:
K = int(input())

s=0
i = 1
while i <=K:
    s = (s*10+7)%K
    if s==0:
        print(i)
        break
    i +=1
if i>K:
    print(-1)

Submission status: Accepted

Solution code:


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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 03/08/2020

from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 174
# C - Repsept

K=int(input())

modsevens=[7]

if K==7 or K==1:
    print(1)
    exit()
else:
    pass

for i in range (1,K):
    a=(modsevens[-1] *10+7)%K
    
    if a==0:
        print(i+1)
        exit()
    else:
        modsevens.append(a)

print(-1)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 174
# C - Repsept

K=int(input())

modsevens=[7]

if K==7 or K==1:
    print(1)
    exit()
else:
    pass

for i in range (1,K+2):
    a=(modsevens[-1] *10+7)%K
    
    if a==0:
        print(i+1)
        exit()
    else:
        modsevens.append(a)

print(-1)

Submission status: Accepted

Solution code:
# N, D = [int(i) for i in input().split()]
K = int(input())
if K % 7 == 0:
  K = K // 7
K = 9 * K
remain = 1
for i in range(10**6):
  remain = (remain*10) % K
  if remain == 1:
    print(i+1)
    break
else:
  print(-1)