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:
N=int(input())
num = 7
i=1
a=[]
prir1=1
while i<=N:
    xx=num%N
    if xx==0:
        print(i)
        prir1=0
        break
    num=10*xx+7
    i+=1
if prir1:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
k = I()
# 0 ~ k-1の値を取る場合がある。
i = 0
value = 7%k
while i < k:
    if value == 0:
        print(i+1)
        exit()
    value = (10*value + 7)%k
    i += 1
print(-1)

Submission status: Accepted

Solution code:
K = int(input())
L = 0
if K % 7 == 0:
  L = 9*K//7
else:
  L = 9*K
  
t = 1
ans = -1
for i in range(1,L,1):
  t = t*10
  if t % L == 1:
    ans = i
    break
  t = t % L
print(ans)

Submission status: Accepted

Solution code:
k = int(input())
cnt = 0
mod = [0]
not_found = 1
while cnt<k+1:
    cnt+=1
    n = mod[-1]*10+7
    mod.append(n%k)
    if n % k == 0:
        not_found = 0
        print(cnt)
        break
if(not_found):
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K=int(input())
S=set()
ans=0

x=7%K
i=1
while True:
    if x==0:
        ans=1
        break
    if x in S:
        break
    else:
        S.add(x)
    x=(x*10+7)%K
    i+=1

print(i if ans else -1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

x = 7%K

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

Submission status: Accepted

Solution code:
K=int(input())
m=0
count=1
chk=0
for i in range(K):
	m=(m*10+7)%K
	if m==0:
		print(count)
		chk=1
		break
	count+=1

if chk==0:
	print(-1)

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    
    a_i = 7
    if a_i % K == 0:
        print(1)
        return

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

main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


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

Submission status: Accepted

Solution code:
K = int(input())
a = 7
flag = True

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

if flag:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())
x = 7
ans = 1
if k%2 == 0 or k%5 ==0:
  print(-1)
  exit()
elif 7%k == 0:
  ans = 1

else:
  for i in range (1,k):
    x = (x*10+7)%k

    if x%k == 0:
      ans = i+1
      break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a = [0]*k
a[0] = 7 % k

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

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

Submission status: Accepted

Solution code:
import time
start=time.time()
k=int(input())
ans=0
x=k
for i in range(10**9):
  while x%10!=7:
    x+=k
    if time.time()-start>=1.9:exit(print(-1))
  x//=10
  if x==0:exit(print(i+1))

Submission status: Accepted

Solution code:
k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
elif k == 1 or k == 7:
    print(1)
else:
    t = 2
    ex = 77
    for i in range(10 ** 8):
        if ex % k == 0:
            break
        ex = (ex % k) * 10 + 7
        t += 1
    print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k=int(input())

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

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    mod = 7 % K
    mods = set([mod])
    if mod == 0:
        print(1)
        exit()
    ans = 1
    while True:
        ans += 1
        mod = (mod * 10 + 7) % K
        if mod == 0:
            print(ans)
            exit()
        elif mod in mods:
            print(-1)
            exit()
        else:
            mods.add(mod)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
#a1= 7 mod K
#a2= a1*10+7 mod K
#a3= a2*10+7 mod K
a = 0
count = -1
for i in range(K):
    a = (7 + a*10) % K
    if a  == 0:
        count=i+1
        break
print(count)

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    if k & 0:
        print(-1)
        return

    r = 7 % k
    l = 0
    while r and l < k:
        r = (r * 10 + 7) % k
        l += 1

    print([l+1, -1][l == k])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

num = 0

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

    num %= K

print(-1)

Submission status: Accepted

Solution code:
K = int(input())
id = 1
cnt = 7
while cnt < K:
    cnt = cnt * 10 + 7
    id += 1

visited = [0] * K
while True:
    remz = (cnt % K)
    if remz == 0:
        break
    visited[remz] += 1
    if visited[remz] > 1:
        id = -1
        break
    cnt = remz * 10 + 7
    id += 1

print(id)

Submission status: Accepted

Solution code:
k=int(input())
A=[0]*k
f=0
for i in range(k):
  if i==0:
    A[i]=7%k
  else:
    A[i]=(10*A[i-1]+7)%k
  
  if A[i]==0:
    f=1
    print(i+1)
    exit()
if not f:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n=input()
test=list(set(n))
#print(test)
if len(test)==1 and test[0]=="7":
    print(len(n))
    sys.exit()
n=int(n)
if n==1:
    print(1)
    sys.exit()
if n%2 ==0:
    print(-1)
    sys.exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    return -1


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

Submission status: Accepted

Solution code:
k = int(input())
a = [None for i in range(10**7) ]

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

for i in range(1,k+1):
    if a[i] == 0:
        ans = i
        break

print(ans)

Submission status: Accepted

Solution code:
k = int(input())

maxV = (10**6)**2

i = 0
sevens = 0
while i < 10**6+1:
    sevens = sevens * 10 + 7
    sevens = sevens % k
    i+=1
    if sevens % k == 0:
        print(i)
        exit()

print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
ans = 0
s = 7

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

print(-1)

Submission status: Accepted

Solution code:
K = int(input())

if K % 2 == 0 or K % 5 == 0:
  print(-1)
else:
  if K % 7 == 0:
    L = 9 * K // 7
  else:
    L = 9 * K
  a = 10 % L
  check = False
  for i in range(L):
    a %= L
    if a == 1:
      print(i + 1)
      check = True
      break
    a *= 10
  if not check:
    print(-1)

Submission status: Accepted

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

print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

extra = 7 % K

#あまり0と出会う前にが同じあまりのものと合うと終わりなのでそれをチェック。
seen = set()
ans = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#C
# 7,77,777･･･=7*(1,11,111･･･)
# 7*(10^i)=7*(10^i-1)/10-1 = 7*(10^i-1)/9 がkで割れる
# 10^iを(9k,7の倍数だったら9k/7)で割ってあまりが１だったら良い
import sys
k=int(input())
if k%7==0:
    k//=7
k*=9
a=10%k
for i in range(k):
    a=a%k
    if a==1:
        print(i+1)
        sys.exit()
    a*=10
print(-1)

Submission status: Accepted

Solution code:
#C
import sys
k=int(input())
s=0

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

Submission status: Accepted

Solution code:
K=int(input())
num=7
ans=-1
for n in range(pow(10,7)):
    if num%K==0:
        ans=n+1
        break
    shou=num//K
    num-=K*shou
    num=int(str(num)+'7')
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    if k % 7 == 0:
        max_k = 9*k//7
    else:
        max_k = 9*k
    if k %2 == 0 or k%5 == 0:
        print(-1)
    while keta < max_k:
        if mod == 0:
            print(keta)
            break
        mod = (mod*10 + 7)%k
        keta += 1


if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    if k % 7 == 0:
        max_k = 9*k//7
    else:
        max_k = 9*k
    while keta < max_k:
        if mod == 0:
            print(keta)
            break
        mod = (mod*10 + 7)%k
        keta += 1
    else:
        print(-1)


if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    while keta < 10**7:
        if mod==0:
            print(keta)
            break
        keta += 1
        mod = (mod*10 + 7)%k
    else:
        print(-1)


if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
k = int(input())
t = 7
#kで割ったあまりは0を除けばk-1種類
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())
i = 0
s = 0
ans = -1

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
L = 0
if K % 7 == 0:
  L = 9*K//7
else:
  L = 9*K
  
ans = -1
s = 10
for i in range(1,L,1):
  if s % L == 1:
    ans = i
    break
  s = s % L * 10
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
K=int(input())
x=7
c=1
visited={7}
while x%K:
    x*=10
    x+=7
    x%=K
    c+=1
    z=x%K
    if z in visited:
        print(-1)
        exit()
    visited.add(x%K)
print(c)

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
    #常に余りを用いる　⇒　10**7桁の演算
    t = (t*10 + 7)%k
else:print(-1)

"""
else:
for(while)文を
break文で抜ける（真）　⇒　実行しない
forのイテラブルを使い切る、whileが偽になる　⇒　実行する
"""

Submission status: Accepted

Solution code:
K =  int(input())

a = [0]*1000001
ans = -1
a[1] = 7%K

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    k = I()
    ans = -1
    s = 7%k
    if s==0:
        ans = 1
    else:
        for i in range(1,k):
            s = (s*10+7)%k
            if s == 0:
                ans = i+1
                break
    print(ans)

main()

Submission status: Accepted

Solution code:
k = int(input())

a = [7%k]

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

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

print(-1)

Submission status: Accepted

Solution code:
K = int(input())

a = [0] * K
a[0] = 7 % K

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

ans = -1
for i in range(K):
    if a[i] == 0:
        ans = i + 1
        break

print(ans)

Submission status: Accepted

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

    if k % 2 ==0:
        print(-1)
        return
    last = 0
    for i in range(1000000):
        if (last*10 + 7) % k == 0:
            print(i+1)
            return
        last = (last*10 + 7) % k
    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    K = int(input())
    N = 7
    c = 1
    for i in range(10**6):
        if N % K == 0:
            print(c)
            break
        else:
            N = N * 10 + 7
            N %= K
            c += 1
    else:
        print(-1)
resolve()

Submission status: Accepted

Solution code:
K = int(input())

A = 7

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

print(-1)

Submission status: Accepted

Solution code:
k = int(input())
sevens = 7 % k

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
K = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

n = 7 % k
ans = -1
cnt = 1
checked = {n}
while n > 0:
    n = (n * 10 + 7) % k
    cnt += 1
    if n in checked:
        break
    checked.add(n)

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

Submission status: Accepted

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


if K%2==0 or K%5==0:
    print(-1)
    sys.exit()
    
mod=7%K
if mod==0:
    print(1)
    sys.exit()
    
i=1
while True:
    mod=(10*mod+7)%K
    i+=1
    mod=mod%K

    if mod==0:
        print(i)
        break

Submission status: Accepted

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

if k == 1 or k == 7:
  print(1)
  exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

# 7で割り切れる数かを検証するということは1 ~ kで割ると良い
# ただし、毎回10をかけて7を足していると計算できない範囲まで大きくなるので毎回kで割ったあまりを用いる

k = int(input())

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

Submission status: Accepted

Solution code:
import sys

K = int(input())
a = []
i = 1

a.append(7 % K)
while i < K:
    a.append((a[i-1]*10+7) % K)
    i += 1

i = 0
while i < K:
    if(a[i]==0):
        print(i+1)
        exit(0)
    i += 1

print(-1)

Submission status: Accepted

Solution code:

def main():
    K = int(input())
    cnt = 1
    a = 7%K
    s = {a}
    for i in range(K):
        if a%K == 0:
            print(cnt)
            return
        a = a*10 + 7
        a = a % K
        if a in s:
            print(-1)
            return
        s.add(a)
        cnt += 1

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# Ai ≡ 0 (mod k) A1 = 7, A2 = 77, A3 = 777

k = int(input())
if k == 7 or k == 1:
    print(1)
    exit()
# よくわからんからAiをmodKにして試してみる
seven = 7
for i in range(1, 10**6 + 10):
    seven = seven * 10 + 7
    seven %= k
    if seven == 0:
        print(i + 1)
        exit()
print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

Solution code:
K = int(input())

val = 7 % K

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

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

val = 7 % K

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

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

num = 7%K

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

x = 7
ans = 1

#print(7%1)

for i in range(3*n):
  if x%n==0:
    break
  ans+=1
  x= x*10 + 7
  x=x%n
    
if ans < 3*n:
  print(ans)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
 
sevens = 7 % K
count = 1
 
while(sevens % K !=0):
  # 計算桁を減らすために(mod K)で7, 77, 777,,,を計算する
  sevens = sevens * (10 % K) + (7 % K)
  sevens = sevens % K
  
  count += 1
  if count > K:
    count = -1
    break
    
print(count)

Submission status: Accepted

Solution code:
K = int(input())
 
sevens = 7 % K
count = 1
 
while(sevens % K !=0):
  sevens = sevens * (10 % K) + (7 % K)
  sevens = sevens % K
  count += 1
  if count > K:
    count = -1
    break
    
print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

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

flag = 1
for i in range(1, K+1):
    if a[i] == 0:
        print(i)
        flag = 0
        break
if flag:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

k = int(input())
value = 7

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

if not isTrue:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
K = int(input())

mod = 7
number = 1

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

if mod % K == 0:
    print(number)
else:
    print(-1)

Submission status: Accepted

Solution code:
K = int(input())
tmp = 1
ans = -1

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

for i in range(10 ** 7):
    tmp *= 10
    tmp = tmp % L
    if tmp == 1:
        ans = i + 1
        break
   
print(ans)

Submission status: Accepted

Solution code:
K = int(input())

ans = 1
num = 0
seven = 7

if not K%2:
    print(-1)
else:
    for i in range(K):
        num = num + seven
        seven = seven*10%K
        num = num%K
        if num == 0:
            print(ans)
            break
        ans += 1
    else:
        print(-1)

Submission status: Accepted

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

while a != 0:
  ans += 1
  a = (10*a + 7) % k
  
  if ans == 10**6:
    ans = -1
    break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K=int(input())

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


if flag==0:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()


def main():
    k = int(input())
    cur = 0

    for i in range(1, 10 ** 7):
        cur *= 10
        cur += 7
        cur %= k

        if cur == 0:
            print(i)
            return
    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


resolve()

Submission status: Accepted

Solution code:
#数列が与えられたら漸化式を作る
#a1 = 7, ai = 10 * a(i - 1) + 7 (i >= 2)
K = int(input())
a = [7 % K] #a1 mod K
for i in range(K - 1): #a2 - aK
  a.append((10 * a[i] + 7) % K) #mod K
for i in range(K):
  if a[i] == 0:
    print(i + 1)
    break
else: print(-1)

Submission status: Accepted

Solution code:
K = int(input())

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

elif K%7 == 0:
    x = -1
    b = 9*K/7
    c = 10%b

    for i in range(1,K+1):
        if c ==1:
            x = i
            break
        c = (c*10)%b

    print(x)

else:
    x = -1
    b = 9*K
    c = 10%b
    for i in range(1,K+1):
        if c ==1:
            x = i
            break
        c = (c*10)%b
        #print(c)
    print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

k=int(input())

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

Submission status: Accepted

Solution code:

k=int(input())

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

Submission status: Accepted

Solution code:

k=int(input())

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