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())
aa=7
ans = 1

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

Submission status: Accepted

Solution code:
# input here
_INPUT = """\
101
"""

def main():
    # -*- coding: utf-8 -*-
    # スペース区切りの整数の入力
    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)

if __name__ == '__main__':
    import io
    import sys
    import math

    #sys.stdin = io.StringIO(_INPUT)
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(k):
    a_mod = 0
    pow_10 = 7
    for i in range(1000000):
        a_mod += pow_10
        a_mod %= k
        if a_mod == 0:
            return i + 1
        pow_10 *= 10
        pow_10 %= k
    return -1


def main():
    k = int(input())
    res = solve(k)
    print(res)


def test():
    assert solve(101) == 4
    assert solve(2) == -1
    assert solve(999983) == 999982


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc174/submissions/15768313 さんの回答、参照

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

Submission status: Accepted

Solution code:
K = int(input())

s = set()
seven = 7
ans = 1
while seven % K != 0:
    seven = seven * 10 + 7
    seven %= K
    if seven in s:
        ans = -1
        break
    s.add(seven)
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
num = 7
k = int(input())
count=1
# i=1
while(True):
    if((num%k)==0):
        print(count)
        break
    if(count>k):
        print(-1)
        break
    num = (num*10+7)%k
    count+=1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
ans = -1
a = [7 % K]
for i in range(1, K):
    a.append((a[i - 1] * 10 + 7) % K)
for i, n in enumerate(a, 1):
    if n == 0:
        ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
'''
Date         : 2020-08-08 23:01:16
Author       : ssyze
Description  : 
'''
from math import *
k = int(input())
x = 7
cnt = 1
while x % k != 0:
    x = (x * 10 + 7) % k
    cnt += 1
    if cnt >= 10**6 + 5:
        break
if cnt >= 10**6 + 5:
    print("-1")
else:
    print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import functools

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

mod=0

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

Submission status: Accepted

Solution code:
K=int(input())

if K%2==0:
    print(-1)
    exit(0)
    
ans=[0]*(pow(10,6)+1)
ans[0]=0

for i in range(1,pow(10,6)):
    ans[i]=(ans[i-1]*10+7)%K
    if ans[i]==0:
        print(i)
        exit(0)

print(-1)

Submission status: Accepted

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

    mod = 0

    for i in range(1, K+1):
        mod = (10 * mod + 7) % K
        if mod == 0:
            print(i)
            return

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
K = int(input())
seven = 7 % K
c = 0
p = 1 % K
found = False
for i in range(K + 1):
  c = (c + p % K) % K
  if ((seven * c) % K == 0):
    found = True
    print(i + 1)
    break
  p = (p * (10 % K) ) % K
  #print(i, p)

if not found:
  print(-1)

Submission status: Accepted

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

    m = 7 % K

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

def main():
    
    K = I()
    if K%2 == 0:
        print('-1')
        sys.exit()
    
    ans = 1
    n = 7
    for i in range(K):
        
        if n%K ==0:
            print(ans)
            break
        
        n = (10*n + 7)%K  
        ans += 1
    
    else:
        print('-1')

main()

Submission status: Accepted

Solution code:

k = int(input())

surplus = 0
ans = 1
while 1:
    if ans > k:
        print(-1)
        exit()
    surplus = ((surplus * 10) + 7) % k
    if surplus == 0:
        break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
K=int(input())
L=9*K
if L%7==0:
  L = L//7
n = 1
for i in range(1,K+1):
  n = n * 10 % L
  if n == 1:
    print(i)
    sys.exit()
print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def calc_term(k):
    # [i] = 10 ^ i (mod k) 
    power_ten_mod_k = [1] * k
    for i in range(1, k):
        power_ten_mod_k[i] = (10 * power_ten_mod_k[i-1]) % k
    # [i] = 111...11 (1 が i + 1 個) (mod k)
    one_consec_mod_k = power_ten_mod_k[:]
    for i in range(1, k):
        one_consec_mod_k[i] = (one_consec_mod_k[i] + one_consec_mod_k[i-1]) % k
    for i in range(k):
        if one_consec_mod_k[i] == 0:
            return i + 1
    return -1
    


def main():
    k = int(input())
    if k % 7 == 0:
        k //= 7
    if k == 1:
        print(1)
    else:
        print(calc_term(k))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# from collections import defaultdict


# # 試し割り法による素因数分解
# # defaultdictにつっこむやつ
# def prime_factorize_dict(n):
#     dd = defaultdict(int)
#     while n % 2 == 0:
#         dd[2] += 1
#         n //= 2
#     f = 3
#     while f * f <= n:
#         if n % f == 0:
#             dd[f] += 1
#             n //= f
#         else:
#             f += 2
#     if n != 1:
#         dd[n] += 1
#     return dd


k = int(input())
# print(prime_factorize_dict(k))
if k % 2 == 0:
    print(-1)
else:
    count = 1
    if k == 1 or k == 7:
        print(1)
    else:
        now = 7 % k
        while (1):
            count += 1
            now = ((now * 10 + 7) % k) % k
            if now == 0:
                print(count)
                exit()
            if count >= 1000000:
                print(-1)
                exit()

Submission status: Accepted

Solution code:
k = int(input())
ans = 1
seen = set()
mod = 7%k
while mod != 0 and mod not in seen:
    seen.add(mod)
    mod = (10*mod + 7)%k
    ans += 1

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

Submission status: Accepted

Solution code:
K = int(input())
t = 7 % K
cnt = 1
while t != 0 and cnt < 10**6+10:
    t *= 10
    t += 7
    t %= K
    cnt += 1
if cnt == 10**6+10:
    cnt = -1
print(cnt)

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    visited = [False]*K

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

        if visited[r]:
            print(-1)
            exit()
        
        visited[r] = True
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

step = 0
n = 0
k = int(input())
l = [0]*k
while True:
  step += 1
  n = (n * 10 + 7) % k
  l[n] += 1
  if n == 0:
    break
  elif l[n] >= 2:
    step = -1
    break
print(step)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def makedivisor(N):  # 約数列挙
    p, upper, lower = 1, [], []
    while p * p <= N:
        if N % p == 0:
            lower.append(p)
            if p * p != N:
                upper.append(N // p)
        p += 1
    return lower + upper[::-1]


def totient(N):  # オイラーのトーシェント関数
    p, phi = 2, N
    while p * p <= N:
        if N % p == 0:
            phi = phi // p * (p - 1)
        while N % p == 0:
            N //= p
        p += 1
    if N > 1:
        phi = phi // N * (N - 1)
    return phi


k = int(input()) * 9

# 解説AC オイラーの定理 O(n**0.5)?
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
if k % 7 == 0:
    k //= 7

cnt = totient(k)
num = makedivisor(cnt)
for i in num:
    if pow(10, i, k) == 1:
        print(i)
        break

Submission status: Accepted

Solution code:
def makedivisor(N):  # 約数列挙
    p, upper, lower = 1, [], []
    while p * p <= N:
        if N % p == 0:
            lower.append(p)
            if p * p != N:
                upper.append(N // p)
        p += 1
    return lower + upper[::-1]


def totient(N):  # オイラーのトーシェント関数
    p, phi = 2, N
    while p * p <= N:
        if N % p == 0:
            phi = phi // p * (p - 1)
        while N % p == 0:
            N //= p
        p += 1
    if N > 1:
        phi = phi // N * (N - 1)
    return phi

k = int(input()) * 9

# 解説AC オイラーの定理 O(n**0.5)
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
if k % 7 == 0:
    k //= 7

cnt = totient(k)
num = makedivisor(cnt)
for i in num:
    if pow(10, i, k) == 1:
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
    K = II()
    d = dict()
    value = 7
    ans = 0
    r = 0
    flag = False
    while not r in d:
        d[r] = True
        r = r*10+7
        r = r % K
        ans += 1
        if r == 0 :
            flag=True
            break
    if flag:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
K = int(input())

out=-1

if K%7==0:
    dammy = K//7
    # print(dammy)
    for i in range(1,10**6):
        #if (10**i -1) % 9 ==0:
        if pow(10,i,9*dammy)==1:
             out=i
             break

else:
    for i in range(1,10**6):
        #if (10**i -1) % (9*K)==0:
        if pow(10,i,9*K)==1:
            out=i
            break

print(out)

Submission status: Accepted

Solution code:
K = int(input())
 
x = []
x.append(7%K)
for i in range(1,K):
  x.append((x[i-1]*10+7)%K)

for i,n in enumerate(x):
  if n == 0:
    print(i + 1)
    exit()
print(-1)

Submission status: Accepted

Solution code:
import sys
K=int(input())
a = [7%K]
for k in range(1, K+1):
    temp = (a[k-1]*10+7)%K
    a.append(temp)
for k in range(K+1):
    if a[k]==0:
        print(k+1)
        sys.exit()
print(-1)

Submission status: Accepted

Solution code:
k = int(input())

# 解説AC
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

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

Submission status: Accepted

Solution code:
def solve():
    K = int(input())
    if K % 10 not in [1, 3, 7, 9]:
        print(-1)
        return

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

    print(-1)

solve()

Submission status: Accepted

Solution code:
k = int(input())

# 解説AC
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
K = int(input())
ans = -1
sup = 7
if 7 % K == 0:
    print(1)
    import sys
    sys.exit()
for i in range(2, K+2):
    sup = 10 * sup + 7
    sup %= K
    if sup == 0:
        ans = i
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

a = [7 % K]
if a[-1] == 0:
    print(1)
    exit()

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

Submission status: Accepted

Solution code:
V = 7
K = int(input())
A = 1
f = False
for i in range(1000005):
  if V % K == 0:
    f = True
    break
  A += 1
  V *= 10
  V += 7
  V %= K
print(A if f else -1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
k = int(input())
i, a = 1, 7
a %= k
while a != 0:
    i += 1
    a = (10 * a + 7) % k
    if i > k:
        i = -1
        break

print(i)

Submission status: Accepted

Solution code:
n=int(input())
ans=0
se=set()
for i in range(1,n+1):
    ans=ans*10+7
    ans=ans%n

    if ans==0:
        print(i)
        quit()
    if ans in se:
        break
    se.add(ans)
print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(K):
    rem = 7
    for j in range(K):
        if rem % K == 0:
            return j+1
        rem = (10*rem + 7) % K 
    return -1

K = int(input())
print(main(K))

Submission status: Accepted

Solution code:
k = int(input())
i = 1
a = 7
a = a % k
while a != 0:
  i += 1
  a = (10*a + 7) % k
  if i == 10**6:
    i = -1
    break

print(i)

Submission status: Accepted

Solution code:
K = int(input())

mod_even = K % 2
mod_fifth = K % 5
mod_seven = K % 7
if mod_even == 0:
  print(-1)
elif mod_fifth == 0:
  print(-1)    
else:
  kk = 0
  if mod_seven == 0:
    kk = int(9*K/7)
  else:
    kk = int(9*K)
  count = 0
  remainder = 0
  kazu = int(10)
  while(1):
    count = count + 1
    remainder = kazu % kk
    if remainder == 1:
      print(count)
      break
    else:
      kazu = int(remainder*10)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
m = 7 % K
cnt = 1
d = 10 % K
while True:
    if m == 0:
        break
    cnt += 1
    m = (m+7*d)%K
    d = d*10%K
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
n = 10**6
cnt = 0
mod = k
if k%2 == 0 or k%5 == 0:
    print(-1)
    exit()
while mod != 0:
    mod = (mod*10+7) % k
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.buffer.readline
k = int(input())
t = 7
for i in range(1, k + 1):
    if not t % k:
        print(i)
        exit()
    t = (t * 10 + 7) % k
print(-1)

Submission status: Accepted

Solution code:
k = int(input())
m = 7 % k 
s = set()
cnt = 1
while(1):
    if m == 0:
        print(cnt)
        break
    elif m in s:
        print(-1)
        break
    else:
        s.add(m)
    m = ((m * (10 % k)) % k + 7 % k) % k
    cnt += 1

Submission status: Accepted

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

k = int(input())
s = 7 % k
for i in range(1, k + 1):
	if not s:
		exit(print(i))
	s = (s + 7 * pow(10, i, k)) % k
print(-1)

Submission status: Accepted

Solution code:
# C Repsept

k = int(input())

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

print(-1)

Submission status: Accepted

Solution code:

K = int(input())
cur = 7
for n in range(K):
    if cur % K != 0:
        cur = (cur * 10 + 7) % K
    else:
        print(n + 1)
        break
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

K = int(input())
tmp = 0
for i in range(1,10**7):
    tmp = (tmp*10+7)%K
    if tmp == 0:
        print(i)
        sys.exit()
        
print(-1)

Submission status: Accepted

Solution code:
m = int(input())
p = 0
for j in range(1, m+1):
    p = (p * 10 + 7) % m
    if p == 0:
        print(j)
        exit()
print("-1")

Submission status: Accepted

Solution code:
k = int(input())
#k, x = map(int, input().split())
#al = list(map(int, input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

l = (9*k//7) if k % 7 == 0 else 9*k

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys 
# sys.stdin = open('input.txt', 'r')  
# sys.stdout = open('output.txt', 'w') 
n = int(input())
sev = '7'
ans = 1
while ans <= 1000000:
	if int(sev) % n == 0:
		print(ans)
		exit()
	ans = ans + 1
	sev += '7'
	sev = str(int(sev) % n)
	# print(sev)
print(str(-1))

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
k = ni()

if k%2==0 or k%5==0:
    print(-1)
    exit()
if k%7==0:
    L=9*k//7
else:
    L=9*k
tmp=1
for i in range(1,10**6):
    tmp = tmp*10 %L
    if tmp==1:
        print(i)
        break
else:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

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

t = 10%mod
i = 1
while t != 1:
    i += 1
    t = t*10%mod
print(i)

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
k = ni()
a = 0
for i in range(10**6):
    a=(a+7*pow(10,i,k))%k
    if a== 0:
        print(i+1)
        break
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
k = int(input())
ans = -1
x = 7

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    K = I()

    rem = 7 % K
    ans = 0
    is_ok = True
    seen = [False] * K
    while rem != 0:
        if seen[rem]:
            is_ok = False
            break
        seen[rem] = True
        rem = rem * 10 + 7
        rem %= K
        ans += 1

    if is_ok:
        print(ans + 1)
    else:
        print(-1)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

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

Submission status: Accepted

Solution code:
# 2, 5 以外にも実現不能なのがあるかも？ Modループして調べる場合。
def main():
    k = int(input())
    tmp = 7 % k
    digits = 1
    rems = set()
    while tmp != 0:
        if tmp in rems:
            return - 1
        rems.add(tmp)
        tmp = (tmp * 10 + 7) % k
        digits += 1
    return digits


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

def calculate(k):

    res = 1

    n = 7

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

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

    while n % k > 0:
        n = n % k
        n = n * 10 + 7
        res += 1

    print(res)

calculate(K)

Submission status: Accepted

Solution code:
K = int(input())

def calculate(k):

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

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

    res = 1

    m = (((10 ** res) - 1) // 9) * 7


    while m % k > 0:
        res += 1
        m = m % k
        m = m * 10 + 7

    print(res)


calculate(K)

Submission status: Accepted

Solution code:
K = int(input())

p = 0
res = -1
for i in range(10 ** 6):
    p *= 10
    p += 7
    p %= K
    if p == 0:
        res = i + 1
        break

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
K=int(input())

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

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

else:
    surplus=1
    for i in range(1,L):
        surplus=(surplus*10)%L
        if surplus==1:
            print(i)
            break

Submission status: Accepted

Solution code:
K = int(input())

count = -1
n = 7
for i in range(K):
    if n % K == 0:
        count = i+1
        break
    n = int(str(n)+'7')
    n %= K
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

answer = -1
x = 7
for index in range(k) :
  if x % k == 0:
    answer = index + 1
    break
  x = (10 * x + 7) % k
  
print(answer)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
k = int(input())

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

print(ans)

Submission status: Accepted

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

k = int(input())
print(solve(k))

Submission status: Accepted

Solution code:
K = int(input().rstrip())
n = 1
if K%7==0:
    L = 9 * K / 7
else:
    L = 9 * K
R = 10 ** n
s = set()
if K == 1 or K == 7:
    print(1)
else:
    while R!=1:
        R = (10 * R) % L
        n += 1
        if R in s:
            print(-1)
            break
        else:
            s.add(R)
    else:
        print(n)

Submission status: Accepted

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

Submission status: Accepted

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

def solve():
    K = int(input())
    a = 7%K
    i = 1
    Kset = set()
    Kset.add(a)
    while a!=0:
        a = (a*10+7)%K
        i += 1
        if a in Kset:
            print(-1)
            return
        Kset.add(a)
    print(i)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    K=I()
    if K%2==0 or K%5==0:
        print(-1)
        exit()
    a=7
    ans=1
    for i in range(1000000):
        if a%K==0:
            break
        else:
            a=(a*10+7)%K
            ans+=1
            
    print(ans)
    

main()

Submission status: Accepted

Solution code:
# 解答
K = int(input())
A = 7 % K 

flag = False
for i in range(1, K+1):
  if A == 0:
    flag = True
    break
  A = (A*10 + 7) % K

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

Submission status: Accepted

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

print(order)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
  print(-1)
else: 
    state = 7 
    state %= K
    cou = 1
    while True:
        if state == 0:
            print(cou)
            break
        state = state *  10 + 7
        state %= K 
        cou+= 1

Submission status: Accepted

Solution code:
k = int(input())

arr = [0] * (k+1)
r = 7 % k
ans = 1

while arr[r] == 0:
    if r == 0:
        print(ans)
        exit()
    arr[r] += 1
    r = (10 * r + 7) % k
    ans += 1

print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

s = '7' * len(str(K))
if int(s) < K:
    s += '7'
ans = len(s)
s = int(s)

while True:
    s = s % K
    if s == 0:
        print(ans)
        exit()
    s = s * 10 + 7
    ans += 1

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())
cnt = 1
mod = 7

for _ in range(k):
    if mod % k == 0:
        break
    cnt += 1
    mod = (mod * 10 + 7) % k

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