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:
K = int(input())

ans = 1
x = 7
useds = [0] * (10**6+5)
useds[x] = 1
while True:
    if x%K == 0:
        print(ans)
        break
    x = (x*10 + 7) % K
    ans += 1
    if useds[x]:
        print(-1)
        break
    useds[x] = 1

Submission status: Accepted

Solution code:

import collections


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

if k%2 == 0 or k%5 ==0:
    print(-1)
else:
    a = 7%k
    if a == 0:
        print(1)
    else:
        for i in range(2, 10000000):
            a = (10*a+7)%k
            if a == 0:
                print(i)
                sys.exit()
        print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

INF = 10**8

w = 0
pows = 1
for i in range(INF):
  w += 7 * pows
  pows = pows * 10 % K
  w %= K
  if w == 0:
    print(i+1)
    break
  else:
    if w in hist:
      print(-1)
      break
    else:
      hist.add(w)
      
#print(hist)

Submission status: Accepted

Solution code:
# def div(n):
#     ans = []
#     for i in range(1,int(n**(1/2)+2)):
#         if n%i == 0:
#             ans.append(i)
#             ans.append(n//i)
#     ans = set(ans)
#     return ans

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

K = int(input())

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

Submission status: Accepted

Solution code:
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
from decimal import Decimal
from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7


k=int(data())
cnt=7
for i in range(1000001):
    if cnt%k==0:
        out(i+1)
        exit()
    cnt=(cnt*10+7)%k
out(-1)

Submission status: Accepted

Solution code:
from math import gcd

x=int(input())
if gcd(x,10)!=1:
    print(-1)
    exit(0)

n=7
res=1
while n%x!=0:
    res+=1
    n*=10
    n+=7
    n%=x

print(res)

Submission status: Accepted

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

k = int(input())
if k%2==0 or k%5==0:
    print(-1)
else:
    ret = 1
    res = 7%k
    while res != 0:
        res = (res * 10 + 7) % k
        ret += 1
    print(ret)

Submission status: Accepted

Solution code:
n=int(input())
if(n%2==0 or n%5==0):
    print(-1)
else:
    a=7 
    ans=1
    flag=1  
    while(flag):
        if(a%n==0):
            print(ans)
            flag=0
            break 
        else:
            ans+=1 
            s=str(a)
            s1='7'
            s2=int(s+s1)
            a=(int(s2))%n

Submission status: Accepted

Solution code:

N = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())
mod7 = 7%k
mod10= 10%k

mod = mod7
mod10times = mod7

if mod%k==0:
    print(1)
else:

    for i in range(2,2000000):
        mod10times = mod10times*mod10%k
        mod = mod10times+mod%k

        if  mod%k==0:
            break

    if i==1999999:
        print(-1)
    else:
        print(i)

Submission status: Accepted

Solution code:
K = int(input())
ans = 1
X = 7
cnt = K
while(cnt > 0):
#     print('rem={}'.format(X%K))
    rem = X % K
    if rem == 0:
        print(ans)
        break
    else:
        ans += 1
        X = rem*10 + 7 
        cnt -= 1

if rem != 0:
    print(-1)

Submission status: Accepted

Solution code:
import sys
from math import sqrt, gcd, ceil, log
# from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
# from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

# sys.setrecursionlimit(5*10**6)

def f(n):
	i = 0
	while n%10 == 7:
		n //= 10
		i += 1
	return((n,i))
def f2(a, b):
	return(b + [0, 10][a > b] - a)
	
def main():
	n = int(input()); 
	dic = defaultdict(int)
	for i in range(1, 10):
		for j in (1, 3, 7, 9):
			dic[(j, (i*j)%10)] = i

	if n%10 in (1, 3, 7, 9):
		t = n%10; ans = 0
		m, ans = f(n*(dic[(t, n%10)]))

		while m != 0:
			m += n*dic[(t, f2(m%10, 7))]
			m, y = f(m)
			ans += y
		print(ans)
	else:print(-1)





if __name__ == "__main__":
	main()

Submission status: Accepted

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

a=(int)(input())
flag=0

a=a*9

cnt=a
qq=a

for i in range(2,a+1):
   # print(i)
    if i*i>a:
        break
    if qq%i==0:
       # print(i)
        cnt=cnt/i*(i-1)
        while qq%i==0:
           # print(qq)
            qq=qq/i

if qq>1:
    cnt=cnt/qq*(qq-1)

#print(cnt)
qwq=(int)(cnt)
t=1

if a%2!=0 and a%5!=0:
    for i in range(1,a+1):
       # t=t*10
        if qwq%i!=0:
            continue
        #print(i)
        if ((10**i-1)*7) % a == 0:
            flag=1
            print(i)
            break
if flag==0:
    print(-1)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

k = int(input())
if k == 7 or k == 1:
    print(1)
elif k % 2 == 0 or k % 5 == 0: print(-1)
else:
    if k % 7 == 0: k = k // 7
    mod = 9*k
    i = 1;
    result = 10;
    while result != 1:
        result = (result * 10) % mod
        i += 1
    print(i)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K=int(input())
S=7
t=S%K
u=1
import sys
for i in range(K+1):
  if t==0:
    print (i+1)
    sys.exit()
  else:
    u=(u*10)%K
    t=(t+(7*u))%K
print (-1)

Submission status: Accepted

Solution code:
def main(k):
  if k % 2 == 0:
    return -1

  num = 1
  cnt = 1
  if k % 7 == 0:
    k = k//7

  for i in range(1000000):
    num = num % k
    if num == 0:
      return cnt
    else:
      num += pow(10, cnt, k)
      cnt += 1
  return -1

k = int(input())
print(main(k))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    K = int(readline())
    if K%2==0:
        print(-1)
    else:
        seven = 7
        amari = set([7])
        ans = 1
        while True:
            seven = seven%K
            if seven==0:
                print(ans)
                break
            else:
                seven = seven*10+7
                if seven in amari:
                    print(-1)
                    break
                ans += 1
                amari.add(seven)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

k = ri()
a = k%10
if a in [1, 3, 7, 9]:
    s = 7
    cnt = 1
    while s%k:
        s = s*10 + 7
        s %= k
        cnt += 1
    print(cnt)
else:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def submit():
    k = int(input())

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

    d = {}
    for t in [1, 3, 7, 9]:
        d[t] = {}
        for i in range(10):
            d[t][t * i % 10] = i
    
    td = k % 10
    curr = 0
    count = 0
    while count == 0 or curr != 0:
        diff = 7 - (curr % 10)
        if diff != 0:
            if diff < 0:
                diff += 10
            coef = d[td][diff]
            curr += coef * k
        curr //= 10
        count += 1

    print(count)
    
submit()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum

def solve():
    K = II()
    one = int(list(str(K))[-1])
    if one % 2 == 0 or one == 5:
        print(-1)
        return

    cnt = 1
    first_k = 7
    while 1:
        if first_k >= K:
            break
        first_k = first_k * 10 + 7
        cnt = cnt + 1
    # print(first_k)

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    K = int(input())
    tmp = 7
    i = 0
    while i < 10**6:
        if tmp % K == 0:
            print(i+1)
            exit()
        else:
            tmp += 7 * pow(10,(i+1),K) % K
            tmp %= K
            i += 1 
    print(-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())

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

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

print(cnt)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
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 print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True

def count_ones(n):

    # to store number of 1s
    # in smallest repunit
    # multiple of the number.
    count = 1;

    # initialize rem with 1
    rem = 7

    if n == 7:
        return 1

    # run loop until
    # rem becomes zero
    while rem != 0:
        # rem*10 + 1 here represents
        # the repunit modulo n
        # print((rem * 10 + 7))
        rem = (rem * 10 + 7) % n
        count = count + 1

        if count > 10 ** 6:
            count = -1
            break

    # when remainder becomes
    # 0 return count
    return count

def main():
    K = I()
    MAX = 10 ** 6

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

    if K == 1:
        print(1)
        return

    print(count_ones(K))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from math import sqrt, gcd, ceil, log
# from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
# from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

# sys.setrecursionlimit(5*10**6)

def f(n):
	i = 0
	while n%10 == 7:
		n //= 10
		i += 1
	return((n,i))
def f2(a, b):
	return(b + [0, 10][a > b] - a)
def main():
	n = int(input()); 
	dic = defaultdict(int)
	for i in range(1, 10):
		for j in (1, 3, 7, 9):
			dic[(j, (i*j)%10)] = i
	# print(dic)
	if n%10 in (1, 3, 7, 9):
		t = n%10; ans = 0
		m, ans = f(n*(dic[(t, n%10)]))
		# print(m, ans)
		while m != 0:
			# print(m, f2(m%10, 7), n*dic[(t, f2(m%10, 7))])
			m += n*dic[(t, f2(m%10, 7))]
			# print(m)

			# print(m, "1")
			m, y = f(m)
			# print(m, y, "2")
			ans += y
		print(ans)



	else:print(-1)
	# print(f2(8, 9))





if __name__ == "__main__":
	main()

Submission status: Accepted

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

import sys


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


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


def main():
    k = int(std_in())
    if k % 2 == 0:
        print(-1)
    elif k % 5 == 0:
        print(-1)
    else:
        i=0
        kk = k
        while 1:
            ks = str(kk)
            if ks.count("7") == len(ks):
                break
            one = kk % 10
            if one == 7:
                kk = kk // 10
                i += 1
            else:
                kk += k
        print(i + len(ks))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve(n):
    r = 0
    s = set()
    i = 0
    while r not in s:
        s.add(r)
        r = (r * 10 + 7) % n
        i += 1
    return i if r == 0 else -1

print(solve(int(input())))

Submission status: Accepted

Solution code:
k = int(input())
if k % 2 == 0:
    print(-1)
elif k in [1,7]:
  	print(1)
else:
  amari = [7]
  tmp = 7
  for i in range(k):
      tmp = (tmp * 10) % k
      if tmp != 7:
          amari.append(tmp%k)
      else:
          break
  amari = amari * ((k//len(amari)) +1)

  ans = amari[0]
  for i in range(1, k+1):
      ans += amari[i]
      if ans % k == 0:
          print(i+1)
          break
  else:
    print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

for i in range(1000000):
    mod += (7*pow(10,i,K))%K
    mod = mod%K
    if mod%K == 0:
        print(i+1)
        sys.exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
K = int(input())
# kouho = [int('7' * i) for i in range(1, 1000)]
ans = -1
t = 7
amari = 7 % K
if K == 1 or K == 7:
    print(1)
    exit(0)
for i in range(1, 1000000):
    t = (t * 10) % K
    a = (t + amari) % K
    if a == 0:
        ans = i + 1
        print(ans)
        exit(0)
    else:
        amari = a
print(ans)

Submission status: Accepted

Solution code:
k = int(input())

s = 0
for n in range(0, 10**6):
  s += 7 * pow(10, n, k)
  if s % k == 0:
    print(n + 1)
    exit()
print('-1')

Submission status: Accepted

Solution code:
k = int(input())
c = 0
t = 7%k
a = [t]*(k+1)

if k%2 == 0 or k%5 == 0:
	print('-1')
elif 7%k == 0:
	print('1')
else:
	for i in range(1,k):
		c += 1
		a[i+1] = (10*a[i] + 7)%k
		if a[i+1] == 0:
			break
	print(c + 1)

Submission status: Accepted

Solution code:
k = int(input())

r = 7
ans = -1
for i in range(1000006):
    r %= k
    if r == 0:
        ans = i+1
        break
    r *= 10
    r += 7
print(ans)

Submission status: Accepted

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

# input = stdin.readline


def isPrime(x):
  f = 2
  while f * f <= x:
    if x % f == 0:
      return False
    f += 1
  return True

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



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

if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

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

if i == k:
    print(-1)
else:
    print(i + 1)

Submission status: Accepted

Solution code:
import copy

# a = get_int()
def get_int():
    return int(input())

# a = get_string()
def get_string():
    return input()

# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]

# a_list = get_string_list():
def get_string_list():
    return input().split()

# a, b = get_int_multi()
def get_int_multi():  # a, b = get_int_multi()
    return map(int, input().split())

# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))

# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    k = get_int()
    prev = 7 % k
    ret = -1

    amari = prev

    if amari == 0:
        ret = 1
    else:

        for i in range(1, k):
            prev = (prev * 10) % k
            amari = (amari + prev) % k

            if amari == 0:
                ret = i+1
                break

    print(ret)


def check(bunshi, k):
    return (bunshi % k == 0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
k= int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    k = kwargs["k"]
    res = 0
    p = 7
    rs = 0

    while True:
        res += 1
        r = p % k
        rs += r
        if rs % k == 0:
            break
        if r == 0 or res > 1000000:
            res = -1
            break
        p = r * 10


    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["k"] = [int(i) for i in cin][0]

    cout = main(kwargs)
    print(cout)

Submission status: Accepted

Solution code:
K = int(input())
i = 1
Num = 7


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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    K = int(input())
    a = 7
    a %= K
    for k in range(K):
        if a % K == 0:
            print(k + 1)
            return
        a = a * 10 + 7
        a %= K
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

K = input()
digit = len(K)
K = int(K)
divided = int(((10**(digit) - 1)*7) / 9)
flag = True
remains = np.zeros(K)
while flag:
  remain = divided%K
  if remain==0:
    flag = False
    print(digit)
  elif remains[remain-1]==1:
    flag = False
    print(-1)
  else:
    remains[remain-1] = 1
    digit += 1
    divided = remain*10 + 7

Submission status: Accepted

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

    if (K % 2 == 0 or K % 5 == 0):
        return -1  # repsept の因数に 2, 5 はない

    repsept = 7 % K
    count = 1
    while repsept % K !=0:
        repsept = ((repsept * 10) + 7) % K
        count += 1
    return count

print(c_repsept())

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

k = inp()

keta = len(str(k))
ans = -1
tmp = 0
for i in range(1000001):
    tmp = ((tmp + (7 * pow(10,i,k)) % k)) % k
    if tmp == 0:
        ans = i+1
        break

print(ans)

Submission status: Accepted

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

d = 7
cnt = 1
mo = d % K
while mo != 0:
    d *= 10
    d %= K
    mo = (mo + d)%K
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
K = int(input())
if (K % 2 == 0 or K % 5 == 0):
    print(-1)
else:
    i = 0
    n = 7
    R = n % K
    while True:
      
        if (R == 0):
            print(i+1)
            exit()

        i += 1
        R = (((10 % K)*R)%K + 7%K) % K

Submission status: Accepted

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


k = int(input())
print(first_multiple(k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

def s(i, K):
    return 7*(pow(10, i+1, K) - 1)

flag = False
tmp = 9*K
for i in range(K+2):
    if s(i, tmp) % tmp == 0:
        flag = True
        print(i+1)
        break

if flag == False:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

K = int(input())
ans = int(math.log10(K)) + 1
X = (10 ** ans - 1) // 9 * 7

while True:
  Y = X % K
  if Y==0:
    print(ans)
    break
  elif K%2==0 or K%5==0:
    print('-1')
    break
  else:
    X = Y * 10 + 7
    ans += 1

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:

m=int(input())

kou = 1

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

    s=7%m
    k=7
    
    while 1:
        if s==0:
            print(kou)
            break
        
        
        k*=10
        k%=m
        s+=k
        s%=m
        
        kou+= 1

Submission status: Accepted

Solution code:
import sys

K = int(input())

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

print(-1)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

INF = 10**9+7

if __name__ == "__main__":
    k = int(input())
    if k%2 == 0:
        print(-1)
        sys.exit()
    cnt = 1
    a = 7
    d = [a]
    for i in range(10**6+1):
        if d[i]%k == 0:
            print(i+1)
            sys.exit()
        b = 10*d[i]
        b%=k
        b+=7
        b%=k
        d.append(b)
    print(-1)

Submission status: Accepted

Solution code:
k=int(input())
q=[7]
Q=[0]

for i in range(k) :
    q.append((q[i]*10)%k)
    if (q[i]+Q[i])%k==0 :
        print(i+1)
        exit()
    Q.append((q[i]+Q[i])%k)
    
else :
    print(-1)

Submission status: Accepted

Solution code:

def main():
    k = int(input())
    res = 1
    s = 7
    used = []
    if k % 2 == 0 or k % 5 == 0:
        return -1
    while True:
        s = s % k
        if s == 0:
            return res
        else:
            s = s*10+7
            res += 1

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

Submission status: Accepted

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

for i in range(1000000):
  s = s*10+7
  s %= k
  if s == 0:
    print(i+1)
    exit()
#nの素数判定
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
if k%7 == 0:
  k//=7
if is_prime(k):
  print(k-1)
  exit()
print(-1)

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    else:
        tmp = 7
        digits = 1
        while tmp % k != 0:
            tmp = (tmp * 10 + 7) % k
            digits += 1
        print(digits)


if __name__ == '__main__':
    main()

Submission status: Accepted

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