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:
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K = ii()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve(string):
    n, k = 7, int(string)
    if k % 2 == 0 or k % 5 == 0:
        return "-1"
    for i in range(k):
        if not n % k:
            return str(i + 1)
        n = (10 * n + 7) % k


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    k = int(string)
    if k % 2 == 0 or k % 5 == 0:
        return "-1"
    n = 7
    for i in range(k):
        if not n % k:
            return str(i + 1)
        n = (10 * n + 7) % k


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
def solve(string):
    k = int(string)
    if k % 2 == 0 or k % 5 == 0:
        return "-1"
    n = 7
    ans = 1
    while n % k:
        n = (10 * n + 7) % k
        ans += 1
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
def resolve():
  a = 7
  for i in range(1,N+1):
    if a % N == 0:
      return i
    a = (a * 10 + 7) % N
  return -1

ans = resolve()
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

k = readInt()

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

print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
    K=i_input()
    a = []
    
    a.append(7 % K)
    for i in range(1,K):
            a.append((a[i-1]*10+7)%K)
    
    for i in range(0,len(a),1):
        if(a[i] == 0):
            print(i+1)
            return

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

# 数列を漸化式と見て、順に余りを計算する
# 余りは循環するので、高々K項まで計算すれば、少なくとも1つの循環を抽出できるので十分
# あとは抽出した余りの列において、0が含まれるか、含まれる場合は何番目かを求める

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

j, ans = 0, -1
for j in range(K):
  if l[j] == 0:
    ans = j + 1
    break
    
print(ans)

Submission status: Accepted

Solution code:
K = int(input())
 
i, a = 0, 0
l = []
for i in range(K):
  a = (10*a + 7) % K
  l.append(a)

j, ans = 0, -1
for j in range(K):
  if l[j] == 0:
    ans = j + 1
    break
    
print(ans)

Submission status: Accepted

Solution code:
K = int(input())
 
i, a = 0, 0
l = []
for i in range(K):
  a = (10*a + 7) % K
  l.append(a)

j, ans = 0, -1
for j in range(K):
  if l[j] == 0:
    ans = j + 1
    break

print(ans)

Submission status: Accepted

Solution code:
k = int(input())
a = [7 % k]
if 7 % k == 0:
    print(1)
    exit()
for i in range(1,k):
    tmp = (a[-1] * 10 +7) % k
    if tmp == 0:
        print(i+1)
        exit()
    else:
        a.append(tmp)
print('-1')

Submission status: Accepted

Solution code:
K = int(input())

i = 7 % K

result = set()
for x in range(K):
    if i == 0:
        print(x + 1)
        exit()
    if i in result:
        print(-1)
        exit()
    else:
        result.add(i)

    i = (i * 10 + 7) % K

print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
a = []
a.append(7 % k)

for i in range(k):
    a.append((a[i] * 10 + 7) % k)

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

print(-1)

Submission status: Accepted

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


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

    for i in range(K):
        if A % K == 0:
            print(i+1)
            return

        A = (A * 10) + 7
        A %= K
    
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

print(solve())

Submission status: Accepted

Solution code:
K = int(input())

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

L = 9 * K

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
K=int(input())

mods=[0]*10**6

temp=7
ans=0
while mods[temp%K]==0 and mods[0]==0:
    mods[temp%K]=1
    ans+=1
    temp*=10
    temp+=7
    temp%=K

print(ans if mods[0]==1 else -1)

Submission status: Accepted

Solution code:
k = int(input())
a = [0 for _ in range(k)]
n = 7

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

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

Submission status: Accepted

Solution code:
# C - Repsept
K = int(input())
tmp = 0
ans = -1
for i in range(1,2*K):
    tmp = (10*tmp+7)%K
    if tmp==0:
        ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
k = int(input())
d1 = k % 10
mae = 0
sd = [0]*10
cnt = 0
if not d1 in (1, 3, 7, 9):
  print(-1)
  exit()
for i in range(1,10) :
  sd[d1 * i % 10] = i
#print(sd)

for j in range(999999):
  d2 = 7 - mae % 10
  s = str(sd[d2] * k + mae)
#  print("mae ", mae,"",sd[d2] * k )
#  print("s1=",s)
  for i in range(len(s)-1, -1, -1):
#    print("s[",i,"]=",s[i])
    if (s[i]) == "7":
      cnt += 1
    else:
      s = s[0:i+1]
      mae = int(s)
#      print("s2=",s)
      break
#    print("i= ",i)
    if i == 0 :
      print(cnt)
      exit()

Submission status: Accepted

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

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)
        break

else:
    print(-1)

Submission status: Accepted

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

k = int(input())

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

Submission status: Accepted

Solution code:
import collections
import sys
import math
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
K=int(input())
if K%2==0 or K%5==0:
  print(-1)
ans=7%K
for i in range(K):
  if ans==0:
    print(i+1)
    exit()
  ans=((ans*10)+7)%K

Submission status: Accepted

Solution code:
k=int(input())
i=1
n=0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC 174 C
k = int(input())

sevens = [0] * k

sevens[0] = 7 % k

if k == 7 or k == 1:
    print(1)
    
else:
    for i in range(1, k):
        new = (sevens[i - 1] * 10 + 7) % k
        sevens[i] = new

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

Submission status: Accepted

Solution code:
K = int(input())
def check(k):
    aaa = 0
    prev = 7%k
    for i in range(0,k):
        aaa+=1
        if prev == 0:
            return(aaa)
        prev = (prev*10+7)%k
    return(-1)
print(check(K))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 1

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
k = int(input())
mod = 7 % k
counter = 1
memo = 1
mod_map = set()
mod_map.add(mod)
while mod != 0:
    mod = ((mod * 10) % k + 7) % k
    if mod not in mod_map:
        mod_map.add(mod)
    else:
        counter = -1
        break
    counter += 1
    if mod == 0:
        break
print(counter)

Submission status: Accepted

Solution code:
k = int(input())
mod = 7 % k
counter = 1
memo = 1
mod_map = set()
mod_map.add(mod)
while mod != 0:
    memo = ((memo % k) * (10 % k)) % k
    mod = (mod + 7 * memo) % k
    if mod not in mod_map:
        mod_map.add(mod)
    else:
        counter = -1
        break
    counter += 1
    if mod == 0:
        break
print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
x = 7%k
s = set()
#i = 1
#while len(s) == 0:
for i in range(1, k+1):
  if x == 0:
    print(i)
    exit()
  #s.add(x)
  x = (x*10+7)%k
  #i += 1
print(-1)

Submission status: Accepted

Solution code:
K = int(input())

first_mod = 7 % K
"""
cnt = 1
if first_mod == 0:
    print(1)
else:
    flg = True
    for i in range(2,K):
        seven = old * 10 + 7
        mod = seven % K
        cnt += 1
        old = seven
        if mod == 0:
            break
        if mod == first_mod:
            flg = False
            break
    if flg:
        print(cnt)
    else:
        print(-1)
"""
old_mod = now_mod = first_mod

cnt = 1
if first_mod == 0:
    print(1)
else:
    flg = False
    for i in range(2,K+1):
        now_mod = ((old_mod * 10) + 7) % K
        cnt += 1
        old_mod = now_mod
        if now_mod == 0:
            flg = True
            break
        if now_mod == first_mod:
            break
    if flg:
        print(cnt)
    else:
        print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
k = int(input())

t = 7
t %= k

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

Submission status: Accepted

Solution code:
K = int(input())
s = 7
flg = False
cnt = 0

for i in range(K+1):
    cnt += 1
    if s % K == 0:
        flg = True
        break
    s *= 10
    s %= K
    s += 7

if flg:
    print(cnt)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

path = set()
a = 0
step = 0
while True:
    step += 1
    a = (a*10 + 7) % K
    if verbose: print (step, ':', a)
    if a == 0:
        print (step)
        break
    if a in path:
        print ('-1')
        break
    path.add(a)

Submission status: Accepted

Solution code:
k = int(input())
if k % 2 == 0:
    print(-1)
else:
    mod = 7 % k
    counter = 1
    memo = 1
    mod_map = set()
    mod_map.add(mod)
    while mod != 0:
        memo = ((memo % k) * (10 % k)) % k
        mod = (mod + 7 * memo) % k
        if mod not in mod_map:
            mod_map.add(mod)
        else:
            counter = -1
            break
        counter += 1
        if mod == 0:
            break
    print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
k = int(input())

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

  print(cnt)

Submission status: Accepted

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


def solve(K: int):
    lastMod = 0
    for i in range(K):
        lastMod = (lastMod*10+7)%K
        if lastMod == 0:
            print(i+1)
            return
    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())

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

else :
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

  print(cnt)

Submission status: Accepted

Solution code:
K = int(input())
a = 7 % K
cnt = 1
while a:
    a = (10*a+7) % K
    cnt += 1
    if K < cnt:
        cnt = -1
        break
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug  7 01:25:53 2020

@author: saito
"""

# %% import phase
#from collections import deque

# %% define phase


# %% input phase
K = int(input())

# %% process phase
r = 0
answer = -1
h = []

for cnt in range(K):
    r = (10*r+7) % K
    if r == 0:
        answer = cnt + 1
        break

# %%output phase
print(answer)

Submission status: Accepted

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

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

print(-1)

Submission status: Accepted

Solution code:
'''
Created on 2020/08/22

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  K=int(pin())
  a=7%K
  for i in range(K):
    if a%K==0:
      print(i+1)
      break
    a=(10*a+7)%K
  else:
    print(-1)
  return 
main()

#解説AC

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def function(x):
    base = 0
    for i in range(1, 10 ** 7):
        base *= 10
        base += 7
        base %= x
        if base == 0:
            return i

    return -1

x = int(input())
print(function(x))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#a_{n} = a_{n-1}*10 + 7
#a_{n}(modK) = a_{n-1}*10(modK) + 7(modK)

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

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

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    k = II()
    sevens = 7%k
    for i in range(1, k+1):
        if sevens % k == 0:
            print(i)
            return
        sevens = (10*sevens + 7)%k
    print(-1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    seven = 7
    already = set()
    cnt = 0
    if k%2==0:
        print(-1)
        return 
    while seven != 0:
        if seven in already:
            print(-1)
            return 
        seven %= k
        already.add(seven)
        cnt += 1 
        if seven != 0:
            seven = seven * 10 + 7
    print(cnt)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    K = int(input())
 
    work = 7
 
    answer = -1
    for i in range(1, K+1):
        i_mod = work % K
        if i_mod == 0 :
            answer = i
            break
        work = i_mod * 10 + 7
    print(answer)
main()

Submission status: Accepted

Solution code:
K = int(input())

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

L = 9 * K

ans = -1

r = 10

for i in range(L):
    r %= L
    if r == 1:
        ans = i + 1
        break
    else:
        r = 10 * r

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

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

L = 9 * K

ans = -1

r = 10

for i in range(L):
    if r % L == 1:
        ans = i + 1
        break
    else:
        r = 10 * (r % L)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
from math import sqrt


def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if 0 == k % 7 else k)
    if 0 == l % 2 or 0 == l % 5:
        return '-1'

    r = phi = l
    for i in range(2, int(sqrt(l)+1)):
        if 0 == r % i:
            phi = phi*(i-1)//i
            while 0 == r % i:
                r //= i
    if 1 < r:
        phi = phi*(r-1)//r

    D = set()
    for d in range(1, int(sqrt(phi)+1)):
        if 0 == phi % d:
            D.add(d)
            D.add(phi//d)

    ret = -1
    for m in sorted(D):
        if 1 == pow(10, m, l):
            ret = m
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

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

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

print('-1')

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    k = int(args[0])

    l = 9*(k//7 if k % 7 == 0 else k)
    if l % 2 == 0 or l % 5 == 0:
        return '-1'

    r = phi = l
    for i in range(2, int(-pow(l, 1/2))):
        if r % i == 0:
            phi = phi//i*(i-1)
            while r % i:
                r //= i

    a = 10 % l
    ret = 1
    while(a != 1):
        a = a*10 % l
        ret += 1
        if phi < ret:
            ret = -1
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

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

Submission status: Accepted

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

    work = 7

    answer = -1
    for i in range(1, K+1):
        i_mod = work % K
        if i_mod == 0 :
            answer = i
            break
        work = i_mod * 10 + 7
    print(answer)
main()

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    k = int(args[0])

    ret = 1
    a = 7 % k
    while(a):
        a = (a*10+7) % k
        ret += 1
        if k < ret:
            ret = -1
            break

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

Solution code:
K = int(input())
a = 7 % K
mods = []

i = 0
found = False
while (i <= K):
    i += 1
    if a == 0:
        print(i)
        found = True
        break
    a = (10 * a + 7) % K

if not found:
    print(-1)

Submission status: Accepted

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

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

print(-1)

Submission status: Accepted

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

# form bisect import bisect_left, bisect_right, insort_left, insort_right
# import numpy as np

# 7.n = 7 * 1.n = 101
7777


def solve(K: int):
    n = 7
    for answer in range(1, K + 1):
        if n % K == 0:
            return answer
        n = 10 * (n % K) + 7
    return -1


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # K = map(int, line.split())
    K = int(next(tokens))  # type: int
    answer = solve(K)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
x = 7%k
cnt = 0

if k%2 ==0:
    print('-1')
else:
    while True:
        cnt += 1
        if x == 0:
            print(cnt)
            break
        elif cnt == k:
            print('-1')
            break
        else:
            x = (x*10+7)%k

Submission status: Accepted

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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

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

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

if not flg:
    print(-1)

Submission status: Accepted

Solution code:
from sys import stdin
k = int(stdin.readline().rstrip())
num = 7
flag = 0
for i in range(1, k + 1):
    if num % k == 0:
        flag = 1
        break
    num = (num * 10 + 7) % k
if flag == 1:
    print(i)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

x = 7%K

for i in range(0,K+1):
    if x== 0:
        print(count)
        break

    count+=1
    x = (x*10+7)%K

if i== K:  
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


def main():
    k = int(input())
    num = 0
    soeji = 0
    ar = [0 for _ in range(k)]

    while True:
        # print(soeji)
        if ar[soeji] > 0:
            break
        ar[soeji] = num
        soeji = (soeji * 10 + 7) % k
        num += 1

    print(-1 if ar[0] == 0 else ar[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc174/tasks/abc174_c
K= int(input())

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