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())
if K%2==0 or K%5==0:
    print(-1)
    exit()
if K==7 or K==1:
    print(1)
    exit()
if K==3:
    print(3)
s=7%K
for i in range(1000001):
    tmp=(10*(K-s))%K
    s=K-tmp+7
    #print(s)
    if s==0 or s==K:
        print(i+2)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
seven = 7
MOD7 = 7 % K
MOD70 = 70 % K
MOD77 = MOD7 + MOD70
if K % 2 == 0:
    print(-1)
elif MOD7 == 0:
    print(1)
else:
    for i in range(1,10**6):
        if MOD77 % K == 0:
            break
        MOD70 = (MOD70 * 10) % K
        MOD77 += MOD70
        MOD77 = MOD77 % K
    if i >= 10**6 - 1:
        print(-1)
    else:
        print(i+1)

Submission status: Accepted

Solution code:
K = int(input())

mod_ans = 7%K
mod_10 = 10%K
mod_7_10 = 7%K
if 7%K == 0:
    print(1)
else:
    for i in range(int(K**(1/1))):
        mod_7_10 = (mod_7_10 * mod_10)%K
        mod_ans = (mod_ans + mod_7_10)%K
#        print(i+2, mod_ans)
        if mod_ans == 0:
            print(i+2)
            break
    else:
        print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def main():
    k = int(input())
    
    if k == 7 or k == 1:
        print(1)
        sys.exit()
    
    r = 7%k
    g = {r}
    ans = 1
    while True:
        ans+=1
        r = (10*r+7)%k
        if r==0:
            print(ans)
            break
        if r in g:
            print(-1)
            break
        else:
            g.add(r)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(readline())

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

Submission status: Accepted

Solution code:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
curr = 0
i = 1
while True:
  curr *= 10
  curr += 7
  curr %= k
  if curr == 0:
    print(i)
    break
  i += 1
  if i > 1000000:
      print(-1)
      break

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

k=I()
dpmod=[0 for i in range(10**6+100)]
dpmod[0]=7%k
for i in range(10**6+100-1):
    dpmod[i+1]=(10*dpmod[i])%k
dp=[0 for i in range(10**6+100)]
dp[0]=7%k
for i in range(10**6+100-1):
    if dp[i]%k==0:
        print(i+1)
        sys.exit()
    dp[i+1]=dp[i]+dpmod[i+1]
print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
n = "7"*(len(str(K))+1)
m = "7"*len(str(K))
p = int(n)
ans = 0
flag = 0
if(K%2==0):
  print("-1")
elif(K==1 or K==11 or K==111 or K==1111 or K==11111 or K==111111):
  print(len(str(K)))
elif(K==7 or K==77 or K==777 or K==7777 or K==77777 or K==777777):
  print(len(str(K)))
else: 
  while(ans <= K):
    ans += 1
    q = p % K
    p = str(q) + "7"
    p = int(p)
    if(q==0):
      print(ans+len(str(K)))
      flag = 1
      break
  if(flag==0):
    print("-1")

Submission status: Accepted

Solution code:
import sys
k=int(input())
d={}
ans=1
mod=7%k
mod1=7%k
d[mod1]=1
ch=0
  
while mod1!=0:
  mod=(mod*10)%k
  mod1=mod1+mod
  if mod1>=k:
    mod1=mod1%k
  if mod1 in d:
    ch+=1
    break
  if mod1 not in d:
    d[mod1]=1
  ans+=1
  
if ch==0:
  print(ans)
else:
  print(-1)

Submission status: Accepted

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

k = int(input())

n = 1

if k % 2  == 0:
    n = -1
else:
    r = 7 % k
    s = r

    while True:
        if r == 0:
            break
        elif n > 1000000:
            n = -1
            break
        else:
            r = (r * 10 + s) % k
            n += 1


print(n)

Submission status: Accepted

Solution code:
k = int(input())

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

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0 and i<=100000000:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
if i>=100000000:
    i=-1
print(i)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
k = int(input())
if k % 2 < 1 or k % 5 < 1:
    print(-1)
else:
    c = 1
    mod = 7 % k
    mop = 7 % k
    while mod > 0:
        mop = mop*10%k
        mod += mop
        mod %= k
        c += 1
    print(c)

Submission status: Accepted

Solution code:
# Coding is about expressing your feeling and there is always a better way to express your feeling _feelme
import sys,math,numpy as np
#sys.stdin,sys.stdout=open('input.txt','r'),open('output.txt','w')
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt
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()
# print('{:.3f}'.format(1),round(1.123456789,4))
# np.set_printoptions(sign=' ',legacy='1.13') # legacy add space at sign position
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(arr, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if arr[mid] == val:return mid
        elif arr[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,arr):
    for i in range(1,n):arr[i]+=arr[i-1]
    return arr;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;


def fun(k):
    current=7
    for i in range(1,10**6):
        if current%k==0:
            return i
        current*=10
        current+=7
        current=current%k
    return -1
k = ii1()
print(fun(k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
now = 1
ans = 7
mod = 10 ** 9 + 7
for i in range(K + 1):
    if ans % K == 0:
        print(now)
        exit()
    now += 1
    # ans += 7 * 10 ** (i + 1)
    # ans %= 10 ** 9 + 7
    # ans += 7 * 10 ** (i + 1) % mod
    ans += 7 * pow(10, i + 1, K) % K


print('-1')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

K = int(input())


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)

    divisors.sort()
    return divisors


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

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

print("-1")
sys.exit()

Submission status: Accepted

Solution code:
from collections import defaultdict

K=int(input())

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

memo=defaultdict(int)
tmp=0
ans=0
while True:    
    tmp=(tmp*10+7)%K
    ans+=1
    if tmp==0:
        print(ans)
        break
    elif memo[tmp]==1:
        print(-1)
        break
    else:
        memo[tmp]+=1

Submission status: Accepted

Solution code:
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    i = 1
    v = 7
    while True:
        if v % K == 0:
            print(i)
            break
        else:
            i += 1
            v = v * 10 + 7
            v %= 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())

mod_set = set()
num = 7
cnt = 1

while True:
    if num % k == 0:
        print(cnt)
        exit()
    else:
        if num % k in mod_set:
            print('-1')
            exit()
        else:
            mod_set.add(num % k)
    num = (num * 10 + 7) % k
    cnt += 1

Submission status: Accepted

Solution code:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    k = int(input())
    tmp = 7
    cnt = 0
    if k%2 == 0 or k%5 == 0:
        print(-1)
        return

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#200802C
X = int(input())
L = len(str(X))
#print(L)


Y = 0

for l in range(L):
    Y += 7*10**l
    
flag = 0
for i in range(1000000):
    Y = Y%X
    #print(i)

    if Y == 0:
        ans = L+i
        flag = 1
        break
    else: 
        Z = Y * 10 + 7
        if Z == Y:
            break
        else:
            Y = Z

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

Submission status: Accepted

Solution code:
N = int(input())

D = 7%N

for i in range (1, N+1):
	if	D == 0:
		print(i)
		exit()
	else:
		D = (10*D+7)%N

print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
k = int(input())
#n, d = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

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

    m *= 10
    m += 7
    if m > k:
        m %= k

print(-1)

Submission status: Accepted

Solution code:
def main(k):
    r0 = 7 % k
    if r0 == 0:
        print(1)
        return
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    rs = [r0]
    while True:
        ri = (10 * rs[-1] + r0) % k
        if ri == 0:
            break
        rs.append(ri)
        if len(rs) >= 3 and rs[-1] == rs[-2] == rs[-3]:
            print(-1)
            return
    print(len(rs) + 1)


main(int(input()))

Submission status: Accepted

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

def main():
    import sys

    K = int( sys.stdin.readline() )

    A = 7
    add_digit = 7
    i = 1
    checked = set()


    while True:
        if A % K == 0:
            print(i)
            return

        elif A in checked:
            print("-1")
            return
        
        checked.add(A)
        add_digit = (add_digit * 10) % K
        
        next_A = add_digit + A
        next_A %= K

        A = next_A
        i += 1


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

k = INT()
l = len(str(k))
if k % 2 == 0:
    print(-1)
    exit()
dp = [-1 for _ in range(10 ** 6 + 100)]
for i in range(10 ** 6 + 100):
    if l > i + 1:
        continue
    elif l == i + 1:
        num = 0
        for _ in range(i):
            num *= 10
            num += 7
        if k > num:
            continue
    if dp[i - 1] == -1:
        num = 0
        for _ in range(i):
            num *= 10
            num += 7
        dp[i] = num % k
    else:
        dp[i] = (dp[i - 1] * 10 + 7) % k
    if dp[i] == 0:
        print(i)
        exit()
print(-1)

Submission status: Accepted

Solution code:
K = int(input())
#最大K回 回せばいい
now = 7
for i in range(K + 2):
    now %= K
    if now == 0: 
        print(i + 1)
        exit()
    now = now * 10 + 7 
print(-1)

Submission status: Accepted

Solution code:
K,=list(map(int, input().split()))
se = 7
fiv = 1
for i in range(1,1000000):
  if K <= se:
    st = i
    break
  fiv *= 10 
  se = se + 7 * fiv
q1 = 7 * fiv % K
q2 = se % K
if q2 == 0:
  print(st)
  exit()
for i in range(st,1000000):
  if q2!=0:
    q1 = (10*q1) % K 
    q2 = (q1+q2)%K
    continue
  print(i)
  exit()  
print("-1")

Submission status: Accepted

Solution code:
#coding:utf-8

k = int(input())

now = 1

if(k%2==0)or(k%5==0):
    print("-1")
else:
    past = 0
    for i in range(1,k+1):
        past = (past * 10 + 7) % k
        if past == 0:
            print("{}".format(i))
            break

Submission status: Accepted

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


def solve(K: int):
    if K % 2 == 0:
        print(-1)
    else:
        num = 7
        cnt = 1
        stop = 10 ** 7
        while cnt < stop:
            if num % K == 0:
                print(cnt)
                return
            else:
                num *= 10
                num += 7
                num %= K
                cnt += 1
        print(-1)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
rest = 7%K
count=1
while (count<=K):
    if rest == 0:
        print(count)
        exit()
    count +=1
    rest = (rest%K*10%K + 7%K)%K
print(-1)

Submission status: Accepted

Solution code:
k = int(input())
f = 7
r = f % k
r_10 = 10 % k
r_7 = 7 % k
n = pow(10, 6)
ans = False
if k % 2 == 0:
    print(-1)
else:
    for i in range(1, n+1):
        if r % k == 0:
            ans = True
            break
        r = (r*r_10 + r_7) % k

    if ans:
        print(i)
    else:
        print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

lst = [1]
for i in range(1, 10**7):
    lst.append((lst[-1]*10) % k)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
import bisect   
setrecursionlimit(10 ** 7)

k = int(input())
now = 7

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

print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
def junkan(x):
    if x == 1:
        return 1
    one = 1
    one *= 10
    for cnt in range(1000001):
        d, m = divmod(one, x)
        if m == 1:
            break
        elif d == 0:
            one *= 10
        else:
            one = m
            one *= 10
        
    return cnt+1

if __name__ == "__main__":
    K = int(input())
    flag = True

    if K%2 == 0 or K%5 == 0:
        flag = False
        print(-1)
    elif K%7 == 0:
        K = K//7
    K = K*9
        
    if flag:
        print(junkan(K))

Submission status: Accepted

Solution code:
time = 1
K = int(input())
sev = 7
while True:
    if K % 2 == 0 or time > K:
        print(-1)
        break
    elif sev % K == 0:
        print(time)
        break
    else:
        sev = sev % K * 10 + 7
        time += 1

Submission status: Accepted

Solution code:
import sys

def main():
    K = int(sys.stdin.readline().rstrip())

    A = [True] * K

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

main()

Submission status: Accepted

Solution code:
import os
import sys
from io import BytesIO, IOBase
# from collections import defaultdict as dd
# from collections import deque as dq
# import itertools as it
# from math import sqrt, log, log2
# from fractions import Fraction
# def primeFactors(n): 
#     ans = []
#     # Print the number of two's that divide n 
#     while n % 2 == 0: 
#         ans.append(2) 
#         n = n / 2
          
#     # n must be odd at this point 
#     # so a skip of 2 ( i = i + 2) can be used 
#     for i in range(3,int(sqrt(n))+1,2): 
          
#         # while i divides n , print i ad divide n 
#         while n % i== 0: 
#             ans.append(i)
#             n = n / i 
              
#     # Condition if n is a prime 
#     # number greater than 2 
#     if n > 2: 
#         ans.append(int(n))

#     return ans 

def main():
    k = int(input())
    if k%2 == 0:
        print(-1)
    else:
        pass
    
        rem = 7%k

        ans = -1
        for i in range(1, 10**7):
            if rem == 0:
                ans = i
                break

            rem = 10*rem + 7
            rem %= k

        print(ans)

        


        




































# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
 
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    NOW=0

    for i in range(1,10**6+3):
        NOW=NOW+7*pow(10,i,K)
        NOW%=K

        if NOW==0:
            print(i)
            break
    else:
        print(-1)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))


K = int(input())
def main():
    k = 7
    count = 1
    re = 1
    if K % 2==0:
        print(-1)
        return
    while True:
        if k % K == 0:
            print(count)
            return
        re =  (re*10)%K
        k = (k+7*re)%K
        count += 1
        if count >= 10**7:
            print(-1)
            return


main()

Submission status: Accepted

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

    ans = 0
    ketasave = 0
    ng = False
    while True:
        for _ in range(9):
            ans += k
            if ans % 10 == 7:
                while ans % 10 == 7:
                    ans -= 7
                    ans //= 10
                    ketasave += 1
                break
        else:
            ng = True
            break

        if ans==0:
            break
            
    print(ketasave if not ng else -1)

main()

Submission status: Accepted

Solution code:
import sys

k = int(input())

if k % 2 == 0:
    print(-1)
    sys.exit()

rest = [7 % k]


for i in range(k):
    rest.append(rest[-1] * 10 % k)

tmp = 0
for i in range(k):
    if (tmp + rest[i]) % k == 0:
        print(i + 1)
        sys.exit()
    else:
        tmp = (tmp + rest[i]) % k
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

# r7 = 7%k
r = 0
for i in range(1,k*10):
    r = (r*10 + 7)%k

    # print('r {} i {}'.format(r,i))
    if r == 0:
        print(i)
        exit()
    # print(n)
print(-1)

Submission status: Accepted

Solution code:
def solve():
  K = int(input())
  if K%2==0 or K%5==0:
    return -1
  ans = 1
  cnt = 7%K
  i = 1
  while cnt!=0:
    cnt += 7*pow(10,i,K)
    cnt %= K
    i += 1
    ans += 1
  return ans
print(solve())

Submission status: Accepted

Solution code:
k = int(input())

s = set()
x, ans = 7 % k, 1
while True:
    if x == 0:
        break

    if x in s:
        ans = -1
        break

    s.add(x)
    x = (x*10+7) % k
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


K = int(input())
modks = [7 % K]
for i in range(1, 10**6 + 100):
    modks.append((modks[-1] + 7 * pow(10, i, K)) % K)


for i, m in enumerate(modks, start=1):
    if m == 0:
        exit(i)
print(-1)

Submission status: Accepted

Solution code:

import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

k = readint()
flag = 1
if k%2==0 or k%5==0:
    flag = 0

if flag:
    a = 7
    a %= k
    i = 1
    while 1:
        if a%k==0:
            print(i)
            exit()
        else:
            a+=7*pow(10,i,k)
            a%=k
            i+=1
else:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())

s = 0
c = 1

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

if c > i+1:
    print('-1')
else:
    print(c)

Submission status: Accepted

Solution code:
K=int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

k = inp()
if k % 2 == 0:
    print(-1)
    sys.exit()
if k % 7 == 0:
    k //= 7
n = 1
cnt = 1
for i in range(1001001):
    n = n % k
    if n == 0:
        print(cnt) 
        sys.exit()
    cnt += 1
    n *= 10
    n += 1 
print(-1)

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    if K % 2 == 0 and K % 5 == 0:
        print(-1)
        exit()
    ans = 0
    ten = 1
    mod = [0] * (10**6+5)
    for i in range(10**6):
        tmp = 7 * ten
        tmp %= K
        mod[i] = tmp
        ten *= 10
        ten %= K

    pre = 0   
    for i in range(10**6):
        pre += mod[i]
        if pre % K == 0:
            print(i+1)
            exit()

    print(-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

ans = 0
x = 7
T = True
while T:
  ans += 1
  #print(x)
  if x % K == 0:
    print(ans)
    quit()
  x = x * 10 + 7
  x %= mod