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: Time Limit Exceeded

Solution code:
K=int(input())
n=len(str(K))
N=int("7"*n)
if K%2==0:
    print(-1)
else:
    while N%K!=0:
        n+=1
        N=N*10+7
        N%=K
    print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

memo = '7'

ans = 1

while int(memo)%n != 0:
    memo = memo + '7'
    ans += 1
    #print(memo)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C

K=int(input())
ans=-1
for i in range(1,10**8):
    tmp=int("7"*i)
    if tmp%K==0:
        ans=i
        break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

n = 7
i = 1

while (i <= 10 ** 6):
    if (n % K == 0):
        print(i)
        exit(0)

    n = n * 10 + 7
    i = i + 1

print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

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

a = 1
i = 1
while True:
    if a % K == 0:
        print(i)
        break
    else:
        a += pow(10,i,K)
        a %= K
        i += 1

Submission status: Time Limit Exceeded

Solution code:
#from math import *
from collections import *
from random import *
from bisect import *
import sys
input=sys.stdin.readline
def lis():
    return list(map(int,input().split()))
def ma():
    return map(int,input().split())
def inp():
    return int(input())
n=inp()
if(n%2==0):
    print(-1)
co=1
while(1):
    r=int('7'*co)
    if(r%n==0):
        break
    co+=1
print(co)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    K = Scanner.int()
    if K % 2 == 0:
        print(-1)
        return
    X = 7
    cnt = 1

    while True:
        if X % K == 0:
            print(cnt)
            return
        cnt += 1
        X = X * 10 + 7
        X %= K


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import bisect
import math
import fractions
import sys
import copy


def L(): return sys.stdin.readline().split()


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


def S(): return list(sys.stdin.readline().rstrip())


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def IR(n): return [I() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def LIR1(n): return [LI1() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def LR(n): return [L() for _ in range(n)]


alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007


def main():
    K = I()
    ans = 1
    tmp = 7

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

    while tmp % K != 0:
        tmp *= 10
        tmp += 7
        tmp %= K
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
i = 1
num = ''

while True:
    num = '7' * i
    
    if int(num) % k == 0:
        break
    
    i += 1

print(i)

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
ans=0
dev=7
while dev%k and ans <=k+3:
    ans+=1
    dev+=(7*(10**ans))%k
if ans==k+4:print(-1)
else:print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

if k % 2 == 0:
    print(-1)
else:
    now = 7
    ans = 1
    md = 7 % k
    while md != 0:
        md *= 10
        md += 7
        md %= k
        ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	K = inputInt()
	if K % 2 == 0:
		print(-1)
		sys.exit()

	targ = ""
	for i in range(100000):
		targ += "7"
		tmp = int(targ)
		if tmp % K == 0:
			print(i+1)
			sys.exit()

	print(-1)




#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
#a,b = map(int,input().split())
#a_L = list(map(int,input().split()))

sevn = "7"
i = 1
while True:
    tmp = int(sevn)
    if tmp%k==0:
        print(i)
        exit()
    sevn += "7"
    i += 1

Submission status: Time Limit Exceeded

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    K = NI()
    ans = 0
    m = 0
    while True:
        m = (m * 10 + 7) % K
        ans += 1
        if m == 0: break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


def solve():
    K = Scanner.int()
    if K % 2 == 0:
        print(-1)
    X = 7
    cnt = 1
    while True:
        if X % K == 0:
            print(cnt)
            return
        cnt += 1
        X = X * 10 + 7
        X %= K


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

if K%2 == 0:
  ans = -1
else:
  ans = 1
  s = 7
  while True:
    if s%K == 0:
      break
    s = s*10 + 7
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b: a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

K = I()

now = 7%K
count = 1

while now:
  now *= 10
  now += 7
  now %= K
  count += 1
  if now == 7%K:
    print(-1)
    exit()
  
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

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

i = 1
v = 7 % K
while v != 0:
	i += 1
	v = (10 * v + 7) % K
print(i)

Submission status: Accepted

Solution code:
k = int(input())


if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    exc = 0
    for i in range(1, 10 ** 8):
        exc = exc * 10 + 7
        exc = exc % k
        if exc % k == 0:
            ans = i
            break
    print(ans)

Submission status: Accepted

Solution code:
k=int(input())

if k%2==0 or k%5==0:
  print(-1)
else:
  s=1
  a=7
  while a%k!=0:
    a=(10*a+7)%k
    s+=1
  print(s)

Submission status: Accepted

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

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

print("-1")

Submission status: Accepted

Solution code:
k = int(input())
start = 7 % k
ans = start
con = 1

if k % 2 == 0 or k % 5 == 0:
  print("-1")
  exit()
while True:
  if ans == 0:
    print(con)
    break
  else:
    con += 1
    ans = ans * 10 + 7
    ans = ans % k
    if ans == start:
      print("-1")
      break

Submission status: Accepted

Solution code:
K = int(input())

powlis = [7*pow(10, i, K) for i in range(K)]
for i in range(K-1):
    powlis[i+1] = (powlis[i] + powlis[i+1]) % K
powlis[0] %= K


try:
    print(powlis.index(0) + 1)
except:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

i = 7%K
se = set([i])
cnt = 1
while True:
  if i == 0:
    print(cnt)
    break
  cnt += 1
  i = (i*10 + 7)%K
  if i in se:
    print(-1)
    break
  else:
    se.add(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod = int(input())
a = {}
b = int(0)
flag = int(0)
ans = int(0)
for i in range(mod):
  b = b * 10 + 7
  b = b % mod
  if b == 0:
    flag = 1
    ans = int(i) + 1
    break
  else:
    pass

if flag == 1:
  print(ans)
else:
  print("-1")

Submission status: Accepted

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

start = j = 7 % K
count = 1

#無限ループ
while True:
    #0の時
    if j == 0:
        print(count)
        exit()
        
    j = 10 * j + 7
    j = j % K
    count += 1
    
    #同じ数のループしているかチェック
    if j == start:
        print(-1)
        exit()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    K = int(readline())
    a = 0
    ans = 0
    for _ in range(K+1):
        a = 10*a+7
        a %= K
        ans += 1
        if a%K == 0:
            break

    if ans == K+1: 
        print(-1)
    else:
        print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
k = int(input())

num = 7 % k
ans = 1
mod = [0 for _ in range(k)]
mod[num] = 1
while(num):
    num = (num * 10 + 7) % k
    if mod[num] > 0:
        ans = -1
        break
    ans += 1
    mod[num] += 1

print(ans)

Submission status: Accepted

Solution code:
k=int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

seen = set()
extra = 7 % K
cnt = 1
seen.add(extra)
while extra != 0:
    extra = (extra * 10 + 7) % K
    if extra in seen:
        print(-1)
        exit()
    seen.add(extra)
    cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    k = int(input())
    if k % 2 == 0:
        print(-1)
        sys.exit()
    rems = defaultdict(int)
    n = 7 % k
    next_digit = 70 % k
    r = 1
    while True:
        if n == 0:
            print(r)
            sys.exit()
        elif rems[n]:
            print(-1)
            sys.exit()
        else:
            rems[n] = 1
            n += next_digit
            n = n % k
            next_digit = (next_digit * 10) % k
            r += 1
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())

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

cnt=num=0
while 1:
  num+=7*pow(10,cnt,k)
  num%=k
  cnt+=1
  if num==0:
    break
print(cnt)

Submission status: Accepted

Solution code:
k=int(input())

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

cnt=num=0
while 1:
  num+=7*pow(10,cnt,k)
  num%=k
  cnt+=1
  if num==0:
    break
print(cnt)

Submission status: Accepted

Solution code:
# author:  Taichicchi
# created: 19.09.2020 00:06:44

import sys

K = int(input())

a = 7 % K

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

Submission status: Accepted

Solution code:
from sys import stdin

input = stdin.readline
import math

def solve():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    cnt = 1
    cur = 7
    while True:
        r = cur % k
        if r == 0:
            print(cnt)
            break
        cur = r * 10 + 7
        cnt += 1

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

ans = -1

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

Submission status: Accepted

Solution code:

K = int(input())


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

else:
    seen = set()
    ans = 1
    num = 7
    while ans <= K:

        mod = num % K
        if mod in seen:
            ans = -1
            break
        else:
            seen.add(mod)
        
        if mod == 0:
            break
        else:
            num = mod * 10 + 7
            ans += 1
    
    print(ans)

Submission status: Accepted

Solution code:
#                               #
    # author : samars_diary #
    # 17-09-2020 │ 16:21:14 #
#                               #

import sys, os.path

#if(os.path.exists('input.txt')):
    #sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    a=ii()
    val=7%a
    for i in range(1,10**7):
        if val==0:
            print(i)
            return
        val=(val*10+7)%a
    print(-1)
for _ in range(1):
    solve()

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

k = int(input())

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

Submission status: Accepted

Solution code:
k = int(input())
x = 7 % k
i = 1
set = set()
is_there = False

while not is_there:
    set.add(x)
    if x == 0:
        print(i)
        break
    x = (x*10+7) % k
    if x in set:
        is_there = True
    set.add(x)
    i += 1
    if x == 0:
        print(i)
        break
else:
    print('-1')

Submission status: Accepted

Solution code:
K = int(input())

a=[7 % K]
for i in range(1, K):
  a.append((10*a[i-1] + 7) % K)

flag = False
for i in range(len(a)):
  if a[i] == 0:
    print(i+1)
    flag = True
    break
if not flag:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC174 C

K=int(input())

res=1
r=7%K
flg=(K%2==0 or K%5==0)
if flg:
    res=-1
while not flg:
    if not r:
        break
    r=(10*r+7)%K
    res+=1
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  K = int(input())
  ans = False
  if K % 2 == 0:
    print(-1)
    exit()
  cnt = 7 % K
  for i in range(1, K+1):
    if cnt == 0:
      ans = True
      print(i)
      exit()
    cnt = (10 * cnt + 7) % K
  if ans == False:
    print(-1)
    exit()
main()

Submission status: Accepted

Solution code:
def calc(k):
    cur = 7 % k
    for i in range(1, k + 1):
        if cur == 0:
            return i
        else:
            cur *= 10
            cur += 7
            cur %= k
    return -1


k = int(input())
print(calc(k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

seven = [0]*K
seven[0] = 7%K
for i in range(1,K):
    seven[i] = (10*seven[i-1]+7)%K


for i in range(K):
    if seven[i] == 0:
        print(i+1)
        exit()
print(-1)

Submission status: Accepted

Solution code:
k = int(input())

def cal(k):
    n = 7
    for i in range(1,10000000):
        if n % k == 0:
            return i
        else:
            n = (n *10 + 7) % k
    return -1

print(cal(k))

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

K = ri()

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

Submission status: Accepted

Solution code:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))

k = ri()
reses=[]
cnt = 1
tmp = 7
for i in range(k+1):
    res = tmp % k
    if res==0:
        print(cnt)
        sys.exit(0)
    tmp = res * 10 + 7
    cnt += 1
print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
k = int(input())
if k % 7 == 0:
    l = 9*k // 7
else:
    l = 9*k
if l % 2 == 0 or l % 5 == 0:
    print(-1)
else:
    pmo = 1
    for i in range(1, l + 1):
        mo = (pmo * 10) % l
        if mo == 1:
            print(i)
            break
        else:
            pmo = mo

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 13:35:45 2020

@author: ezwry
"""

k = int(input())
a = 7

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

print(-1)

Submission status: Accepted

Solution code:
k = int(input())

if 7 % k == 0:
    print(1)
else:
    a = []
    a.append(7 % k)
    t = 0
    for i in range(2, k+1):
        x = (10 * a[i - 2] + 7) % k
        if x == 0:
            print(i)
            break
        else:
            a.append(x)
            t += 1
    if t == k - 1:
        print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

mod = 7
cnt = 0

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

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


k = I()
ans = -1
a = [0] * (k+1)
a[1] = 7 % k
for i in range(2, k+1):
    a[i] = (a[i-1]*10 + 7) % k

for i in range(1, k+1):
    if a[i] == 0:
        print(i)
        exit()
print(-1)