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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print('-1')
  sys.exit()
s = 7
c = 1
while True:
  if s == 0:
    break
  s = (10 * s + 7) % k
  c += 1
print(c)

Submission status: Wrong Answer

Solution code:
k = int(input())
s = 7
c = 1
while True:
  if s == 0:
    break
  s = (10 * s + 7) % k
  c += 1
print(c)

Submission status: Wrong Answer

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

def main():
    input = sys.stdin.readline
    k = int(input())
    if k % 10 == 2 or k % 10 == 4 or k % 10 == 5 or k % 10 == 6 or k % 10 == 8 or k % 10 == 0:
        print(-1)
        exit()
    elif k % 10 == 1:
        tmp = k * 7
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            if tmp // 10 % 10 <= 7:
                num = 7 - tmp // 10 % 10
            elif tmp // 10 % 10 == 8:
                num = 9
            elif tmp // 10 % 10 == 9:
                num = 8
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break
    elif k % 10 == 3:
        tmp = k * 9
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 3 - 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 5 * 10 ** 7:
                print(-1)
                break
    elif k % 10 == 7:
        tmp = k * 1
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) * 7 + 1) % 10
            tmp2 = k * num
            tmp = tmp // 10 + tmp2
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break
    elif k % 10 == 9:
        tmp = k * 3
        ans = 1
        while True:
            if str(tmp).count("7") == len(str(tmp)):
                print(ans + len(str(tmp)) - 1)
                break
            num = ((tmp // 10 % 10) + 3) % 10
            tmp2 = k * num
            ans += 1
            if ans > 10 ** 8:
                print(-1)
                break

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
t = int(input())
if t%2==0 or t%5==0:
    print(-1)
else:
    i=1
    s=7
    while 1:
        if s==0:
            print(i)
            break
        i += 1
        s = (s * 10 + 7) % t
        continue

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
  r=input()
  l=len(r)-1
  k = int(r)
  s=7
  for i in range(1,l):
    s=(s*10+7)
  for i in range(l,k):
    s=(s*10+7)%k
    if s==0:
      print(i+1)
      exit()
  print(-1)
main()

Submission status: Wrong Answer

Solution code:
k = int(input())
s = 7
c = 0
while True:
  if s == 0:
    break
  s = (10 * s + 7) % k
  c += 1
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k = int(input())
if k%2==0 or k%5==0:
    print('-1') 
else:
    a = 0
    for i in range(99983):
        a = (a*10+7) % k
        if a == 0:
            print(i+1)
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
def main():
  r=input()
  l=len(r)
  k = int(r)
  s=7
  for i in range(1,l):
    s=(s*10+7)
  for i in range(l,k):
    s=(s*10+7)%k
    if s==0:
      print(i+1)
      exit()
  print(-1)
main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    import time
    start=time.time()
    K=int(sys.stdin.readline())
    a=0
    
    for i in range(K+1):
        a*=10
        a+=7
        if a%K==0:
            print(len(str(a)))
            break

main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
k = int(input())

m = 7%k
ans = 1
jud = True
p = 70%k
for i in range(k):
    m = (m + p)%k
    ans += 1
    if m == 0:
        break
    p = p*10%k
    if p == 0:
        jud = False
        break
if jud:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import math

K = int(input())
md = 0
if K % 2 == 0:
    print(-1)
    exit()
for i in range(10*6):
    print(md + 7 * 10 ** i)
    a, b = divmod(md + 7 * (10 ** i), K)
    if b == 0:
        print(i + 1)
        exit()
    else:
        md = b
print(-1)

Submission status: Wrong Answer

Solution code:
def solution(K: int) -> int:
    sevens: int = 0
    for i in range(1, K + 1):
        print(sevens)
        sevens = (sevens*10 + 7) % K
        if sevens == 0:
            return i
    return -1


K: int = int(input())

print(solution(K))

Submission status: Wrong Answer

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    k = input_int()
    t = 7
    for i in range(1000000):
        t %= k
        if t == 0:
            print(i + 1)
        t = t * 10 + 7

    print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    k = input_int()
    t = 7
    for i in range(1000000):
        t %= k
        if t == 0:
            print(i + 1)
            exit()
        t = t * 10 + 7

    print(-1)


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

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    import time
    start=time.time()
    K=int(sys.stdin.readline())
    a=7
    while True:
        a*=10
        a+=7
        if a%K==0:
            print(len(str(a)))
            break
    
        if time.time()-start>=1.8:
            print(-1)
            break

main()

Submission status: Wrong Answer

Solution code:
K = int(input())

i = 7

if i % K == 0:
  print(1)
  exit

iCnt = 1
while iCnt <= 1000000:
  iCnt += 1
  i = (i * 10 + 7) % K
  if i % K == 0:
    print(iCnt)
    exit()

print(-1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
K = int(input())

if K == 1:
    print(1)
    exit()

v = 7
M = set([])
for i in range(1, K + 1):
    v = (v * 10 + 7) % K
    if v == 0:
        print(i + 1)
        exit()
    if v not in M:
        M.add(v)
    else:
        print(-1)
        exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    if K%2 == 0 or K%5==0:
        return -1

    while K % 7 == 0:
        K = K // 7
    
    for i in range(1, 10000000):
        x = pow(10, i, K)
        if x == 1:
            return i
    else:
        return -1


if __name__ == "__main__":
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    import time
    start=time.time()
    K=int(sys.stdin.readline())
    s=''
    while True:
        s+='7'
        if int(s)%K==0:
            print(len(s))
            break
    
        if time.time()-start>=1.8:
            print(-1)
            break

main()

Submission status: Wrong Answer

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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


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

    val = 7

    amari = set([7])
    ans = 1
    while True:
        val = val % k
        if val == 0:
            return ans

        val = val * 10 + 7
        if val in amari:
            print(-1)
            break
        ans += 1
        amari.add(val)


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K = int(input())

v = 7
M = set([])
for i in range(1, K + 1):
    v = (v * 10 + 7) % K
    if v == 0:
        print(i + 1)
        exit()
    if v not in M:
        M.add(v)
    else:
        print(-1)
        exit()

Submission status: Wrong Answer

Solution code:
k = int(input())
add = 7
if k % 7 == 0:
    k //= 7
    add = 1
elif k == 1:
    add = 1
ans = 0
now = k % add
while True:
    if ans > k:
        print(-1)
        break
    elif now == 0:
        print(ans+1)
        break
    else:
        now = (now*10 + add) % k
        ans += 1

Submission status: Wrong Answer

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

result = -1
num = 7
K = I()

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

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

Submission status: Wrong Answer

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

if k == 7:
    print(1)
    sys.exit()

remainders = set()
remainder = 7 % k
remainders.add(remainder)

counter = 1
while True:
    counter += 1
    remainder = remainder * 10 % k
    if remainder in remainders:
        print('-1')
        sys.exit()
    remainders.add(remainder)
    if sum(remainders) % k == 0:
        print(counter)
        sys.exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = -1
num = 7
K = I()

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

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

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    K = int(input())
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return True
    ans = 1
    K1 = K % 10
    t = K
    while t:
        # print(ans)
        for i in range(10):
            if (t + K1 * i) % 10 == 7:
                break
        else:
            ans = -1
            break
        t = t + K * i
        while t % 10 == 7:
            t //= 10
            ans += 1
            
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

max_n = 100005
ans = 0
seven = 7
for k in range(1, max_n):
  ak = 7*(10**k-1)/float(9)/K
  if(ak.is_integer()):
    print(k)
    sys.exit()
print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
add = 7
if k % 7 == 0:
    k //= 7
    add = 1
ans = 0
now = add
while True:
    if ans > k:
        print(-1)
        break
    elif now == 0:
        print(ans+1)
        break
    else:
        now = (now*10 + add) % k
        ans += 1

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    if K%2 == 0 or K%5==0:
        return -1
    
    for i in range(1, 10000000):
        x = pow(10, i, K)
        if x == 1:
            return i
    else:
        return -1


if __name__ == "__main__":
    ans = main()
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K = int(input())

def make_num(K=K):
    n = 0
    for c in range(1, K+1):
        n = (n * 10 + 7) % K
        if n == 0:
            return c

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

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

K = int(input())
cnt = 0
now = 0
if K%2==0:
    print(-1)
    exit()
s = set([0])
for _ in range(10**6+5):
    now += pow(10, cnt, K)*7
    now %= K
    if now in s:
        print(cnt)
        break
    s.add(now)
    cnt += 1
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc174/abc174_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    K = i2n()
    while K % 7 == 0:
        K = K // 7
    x = 10 % K
    for i in range(1, K + 10):
        if pow(x, i, K) == 1 % K:
            print(i)
            return
    else:
        print('-1')
    return
 
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc174/abc174_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    K = i2n()
    x = 10 % K
    n = 0
    for i in range(1, K + 10):
        if (n := pow(x, i, K)) % K == 1 % K:
            print(i)
            return
    else:
        print('-1')
    return

main()

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    if K%2 == 0 or K%5==0:
        return -1
    
    for i in range(1, K*100):
        x = pow(10, i, K)
        if x == 1:
            return i
    else:
        return -1


if __name__ == "__main__":
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:

K=int(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

K = int(input())
cnt = 0
now = 0
if K%2==0:
    print(-1)
    exit()
s = set()
for _ in range(10**6+5):
    now += pow(10, cnt, K)*7
    now %= K
    if now in s:
        print(cnt)
        break
    s.add(now)
    cnt += 1
else:
    print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    if K%2 == 0 or K%5==0:
        return -1
    
    for i in range(1, K+10):
        x = pow(10, i, K)
        if x == 1:
            return i
    else:
        return -1


if __name__ == "__main__":
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:

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

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

    if seven_mod == 0:
        print(i+1)
        exit()
    seven_i = seven_mod
print("-1")

Submission status: Wrong Answer

Solution code:
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

Submission status: Wrong Answer

Solution code:
k = int(input())

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

Submission status: Wrong Answer

Solution code:
K = int(input())


if K%2==0 or K%5==0:
    count = -1
else:
    flag=0
    mod = 7
    count = 1
    while flag==0:
        if mod==0:
            flag = 1
        else:
            count += 1
            mod = (mod*10+7) % K

print(count)

Submission status: Wrong Answer

Solution code:

K=int(input())

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

Submission status: Wrong Answer

Solution code:

k = int(input())
if k % 2 == 0:
    print("-1")
    exit()
n = len(str(k))

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

    if seven_mod == 0:
        print(i+1)
        exit()
    seven_i = seven_mod
print("-1")

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    if 10 % K == 0:
        return -1
    
    for i in range(1, K+10):
        x = pow(10, i, K)
        if x == 1:
            return i
    else:
        return -1


if __name__ == "__main__":
    ans = main()
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math as mt
n=int(input())
x=1%n
for i in range(n):
  ten=10%n
  x=((x%n)*ten)%n
  if x==1:
    print(i+1)
    break
else:
  if n==1:
    print(1)
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# # 1 <= K <= 10^6
# K = int(input())
# max_K = pow(10,6)
#
# import math
#
# #最大公約数
# for i in range(0,)
# math.gcd(101, 7777)
#
#
# row = ''
# for i in range(0,max_K):
#     row = row + '7'
#     n_row = int(row)
#     print(n_row)
#
#     if n_row % K == 0:
#         print(i + 1)
#         break
#     elif i == max_K:
#         print("-1")

k = int(input())
if k==1 or k==7:
  print(1)
elif k%2==0:
  print(-1)
else:
  cnt = 1
  pre = 7
  while(True):
    surp = (pre*10+7)%k
    print(surp)
    cnt += 1
    if surp==0:
      break
    if cnt>1000000:
      cnt = -1
      break
    pre = surp
  print(cnt)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def repfunc(x):
    a=x-1
    for i in range(1,x):
        if (x-1)%i==0 and (pow(10,i)-1)%x==0:
            a=i
            break
    return a


k=int(input())
res=1
ans1=0
ans2=0
if k%7==0:
    k//=7
if k%2==0 or k%5==0:
    print(-1)
elif k ==1:
    print(1)
else:
    c=collections.Counter(prime_factorize(k))
    c2=list(c.keys())
    d=[0 for i in range(len(c2))]
    for i in range(len(c2)):
        if c2[i]==3:
            d[i]=pow(3,c[3])
        else:
            d[i]=repfunc(c2[i])
    print(lcm_list(d))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    if 10 % K == 0:
        return -1
    
    for i in range(1, K+10):
        x = pow(10, i, K)
        if x == 1:
            return i


if __name__ == "__main__":
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())


if K%2==0:
    count = -1
else:
    flag=0
    mod = 7
    count = 1
    while flag==0:
        if mod==0:
            flag = 1
        else:
            count += 1
            mod = (mod*10+7) % K

print(count)

Submission status: Wrong Answer

Solution code:
k=int(input())
if k==1 or k==7:
    print(1)

ans = 1
amari = 7%k
s = amari

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

Submission status: Wrong Answer

Solution code:

k=int(input())
n=0
a=0
ss=0
if k%7==0:
  print(1)
elif k%2==0:
  print(-1)
elif k%5==0:
  print(-1)
else:
  while a==0 and n<=10000:
    n+=1
    ss=10*(ss%k)+1
    if ss%k==0:
      a=1
  if a==1:
    print(n)
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())

seven = 7

if n < 7:
  print(-1)
  sys.exit()

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

Submission status: Wrong Answer

Solution code:
K = int(input())


if K%2==0:
    mod = -1
else:
    flag=0
    mod = 7
    count = 1
    while flag==0:
        if mod==0:
            flag = 1
        else:
            count += 1
            mod = (mod*10+7) % K

print(mod)

Submission status: Wrong Answer

Solution code:
K = int(input())

n = 7
i = 1

while i <= K:
    if n%K == 0:
        ans = i
        break
    n = n*10 + 7
    i += 1
    
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
'''     ░░█ ▄▀█ █   █▀ █░█ █▀█ █▀▀ █▀▀   █▀█ ▄▀█ █▀▄▀█  
        █▄█ █▀█ █   ▄█ █▀█ █▀▄ ██▄ ██▄   █▀▄ █▀█ █░▀░█     '''


# [temp1.py] => [29-07-2020 @ 10:25:10] 
# Author & Template by : Udit "luctivud" Gupta
# https://www.linkedin.com/in/udit-gupta-1b7863135/


import math;   from collections import *
import sys;    from functools import reduce
import time;   from itertools import groupby

# sys.setrecursionlimit(10**6)

def input()         : return sys.stdin.readline()
def get_ints()      : return map(int, input().strip().split())
def get_list()      : return list(get_ints())
def get_string()    : return list(input().strip().split())
def printxsp(*args) : return print(*args, end="")
def printsp(*args)  : return print(*args, end=" ")


DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)] 
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1),\
              (+1, +1), (+1, +0), (+1, -1), (+0, +1)]


CAPS_ALPHABETS = {chr(i+ord('A')) : i for i in range(26)}
SMOL_ALPHABETS = {chr(i+ord('a')) : i for i in range(26)}
INF = float('inf')


# Custom input output is now piped through terminal commands.
# for _test_ in range(int(input())): 

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




# print("Time Elapsed: {}".format(float(S34p-S34t)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K = int(input())

cycle = set()
if K % 2 == 0:
    print(-1)
else:
    n = 7
    i = 1
    while n not in cycle:
        if n % K == 0:
            break
        cycle.add(n)
        n = (n * 10 + 7) % K
        i += 1
       
    print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans, num = 1, 7
while 1:
    if num % k == 0:
        print(ans)
        break
    ans += 1
    num = (num % k) * 10 + 7
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():

    input = stdin.readline

    K = int(input())

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

    seven_len = 7

    ans = 0
    while seven_len != 0:
        seven_len = (seven_len * 10 + 7) % K
        ans += 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import product

def main():

    input = stdin.readline

    K = int(input())

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

    seven_len = 7

    seven_len = int(seven_len)

    ans = 0
    while seven_len != 0:
        seven_len = (seven_len * 10 + 7) % K
        ans += 1

    print(ans)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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