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

#     return ans 

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

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

            rem = 10*rem + 7
            rem %= k

        

        


        




































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

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

Submission status: Wrong Answer

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)

while ans == 0:
    num = 7*int(str(1)*i)
    # gcd(, K)
    i += 1
    # print(num, i-1)
    if gcd(num, K) != 1:
        ans = i-1
        break

print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())
c = 1
b = False

while b == False:
  n = 0
  for i in range(c):
    n += 7 * (10 ** i)
  if n % K == 0:
    b = True
    print(c)
  c += 1
  if c > 500:
    print(-1)
    b = True

Submission status: Wrong Answer

Solution code:
k = int(input())

count = 0
ans = 1

while True:
  num = int("7" + "7" * count)
  if ans > 6:
    print(-1)
    break
  if num % k == 0:
    print(ans)
    break
  count += 1
  ans += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

def main():

    k = int(input())
    if k % 2 == 0:
        print('-1')
    else:
        for i in range(1, int(math.sqrt(k))):
            target = int('1' * i) * 7
            if target % k == 0:
                print(i)
                break
        else:
            print(k - 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

k = int(input())

ans = 1
t = '7'

exist = False

if k == 1 :
    exist = True

if k % 3 == 0 or k % 7 == 0 or k % 11 == 0 or k % 13 == 0 or k % 37 == 0 or k % 41 == 0 or k % 101 == 0 or k % 239 == 0 or k % 4649 == 0:

    while int(t) <= 10**6:
        
        # print(t)

        if int(t) % k == 0 :
            exist = True
            break

        t = t + '7'
        ans += 1

if exist == True :
    print(ans)
else :
    print(-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
f = 0
for i in range(1, 1000):
    tmp = "7"*i
    if int(tmp)%n == 0:
        print(i)
        f = 1
        break
if f == 0:
    if n%2 == 0 or n%5 == 0:
        print("-1")
    else:
        print(n-1)

Submission status: Wrong Answer

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

ans,c = 0,0

while 1:
    c+=1
    for i in range(10):
        if ((ans%10)+((n%10)*i)%10)%10==1:
            ans += n*i
            #print(ans,i)
            break
    ans = ans//10
    if ans==0:
        break
print(c)

Submission status: Wrong Answer

Solution code:
k = input()
i = 1
num = 1

if k[-1] == "0" or k[-1] == "2" or k[-1] == "4" or k[-1] == "5" or k[-1] == "6" or k[-1] == "8":
    print("-1")
    exit()

while 1:
    s = str(bin(num))
    if int(s[2:])%int(k) == 0:
        print(i)
        break
    i += 1
    num = num*2+1

Submission status: Wrong Answer

Solution code:
t = int(input())
c = 1
N = 7
f=0
def isPrime(n): 
    if (n <= 1): 
        return False
    for i in range(2, n): 
        if (n % i == 0): 
            return False  
    return True

if isPrime(t): 
    print (-1) 
else: 
    while(N%t !=0):
        c +=1
        N = N*10 + 7
        if(len(str(N))>10000):
            print(-1)
            f=1
            break
    if(f!=1):
        print(c)

Submission status: Wrong Answer

Solution code:
K = int(input())
s = 7
if K % 2 == 0:
    ans = -1
else:
    for i in range(1, 7):
        if s % K == 0:
            ans = i 
            break
        else:
            ans = -1

        s += 7 * (10 ** i)


print(ans)

Submission status: Wrong Answer

Solution code:
K=int(input())


def solve(K):
    from collections import defaultdict
    if K==1:
        return 1
    elif K%2==0 or K%5==0:
        return -1
    elif K%7==0:
        return(solve(K//7) )
        
    else:        
        app = defaultdict(lambda: False)
        broken=False
        for n in range(1,K+1):
            if n==1:
                amari = 7%K
            else:
                amari = (amari + 7*pow(10,n-1,K) )%K
            #print(n,amari)
            if amari==0:
                broken=True
                break
            if app[amari]:
                broken=True
                break
            else:
                app[amari]=True
        if broken:
            return n
        else:
            return -1
        

print(solve(K))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

k = int(input())
if k % 2==0:
    print(-1)
else:
    keta = math.floor((math.log(k ,10))) + 1
    n = keta
    p = 0
    for i in range(keta):
        p += 7*(10**(i))
    if k % 3 == 0:
        while(n%3 != 0):
            n += 1
            p  += 7  *  10**(n-1)
        if p % k ==  0:
            print(n)
        else:
            n += 3
            p  += 777  *  10**(n-1)
    else:
        while(True):
            if p % k ==  0:
                print(n)
                break
            else:
                n += 1
                p  += 7  *  10**(n-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
j = 0
for i in range(K):
    L = 0
    for k in range(i):
        L += 7*10**k
    if L % K == 0 and not L // K == 0:
        print(i)
        break
    else:
        j += 1
if j == K:
    print('-1')

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    K = int(rl())
    
    if K == 2:
        print(-1)
        return
    if K == 7:
        print(1)
        return
    
    mod = 7
    cnt = 1
    while cnt <= 10 ** 8:
        if mod == 0:
            print(cnt)
            return
        mod = (mod * 10 + 7) % K
        cnt += 1
    print(-1)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
K = int(input())
x = [7, 77, 777, 7777, 77777, 777777]
Count = 0
flag="FALSE"
for i in x:
    Count = Count + 1
    if (i % K)==0:
        flag="TRUE"
        break

if flag=="FALSE":
    Count = -1
if K>=777777:
    Count = K - 1
print(Count)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[7,77,777,7777,77777,7777777,77777777,777777777,7777777777,77777777777,777777777777,7777777777777,77777777777777,777777777777777,7777777777777777,77777777777777777,777777777777777777,7777777777777777777,77777777777777777777]
res=0
for i in range(len(l)):
  if l[i]%n==0:
    res=i
    break
if n==999983:
  print(999982)
elif res>0:
  print(res+1)
else:
  print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
t = int(input())
c = 1
N = 7
f=0
def isPrime(n): 
    if (n <= 1): 
        return False
    for i in range(2, n): 
        if (n % i == 0): 
            return False  
    return True

if isPrime(t): 
    print (-1) 
else: 
    while(N%t !=0):
        c +=1
        N = N*10 + 7
        if(len(str(N))>100):
            print(-1)
            f=1
            break
    if(f!=1):
        print(c)

Submission status: Wrong Answer

Solution code:
import math

k = int(input())
if k % 2==0:
    print(-1)
else:
    keta = math.floor((math.log(k ,10))) + 1
    n = keta
    p = 0
    for i in range(keta):
        p += 7*(10**(i))
    if k % 3 == 0:
        while(n%3 != 0):
            n += 1
            p  += 7  *  10**(n-1)
        if p % k ==  0:
            print(n)
        else:
            n += 1
            p  += 777  *  10**(n-1)
    else:
        while(True):
            if p % k ==  0:
                print(n)
                break
            else:
                n += 1
                p  += 7  *  10**(n-1)

Submission status: Wrong Answer

Solution code:
K=int(input())

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

Submission status: Wrong Answer

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

ans,c = 0,0

while 1:
    c+=1
    for i in range(10):
        if ((ans%10)+((n%10)*i)%10)%10==1:
            ans += n*i
            #print(ans,i)
            break
    ans = ans//10
    if ans==0:
        break
print(c)

Submission status: Wrong Answer

Solution code:
k = int(input())
t = [7, 77, 777, 7777, 77777, 777777, 7777777, 77777777, 777777777]
ans = 0
for i in range(len(t)):
    if t[i] % k == 0:
        ans = i+1
        break
if ans == 0 and k % 2 == 0:
    print(-1)
elif ans == 0 and k % 2 != 0:
    print(k - 1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
k = int(input())

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

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
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())

k = INT()
x = 0
for i in range(10**4):
    x = ( x + 7*10**i ) % k
    if x % k == 0:
        print(i+1)
        exit()
if k % 2 != 0 and k % 5 != 0:
    print(k-1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())

count = 0
times=1
n = 0

while True:
    n += 7*times
    if n>10**6:
        break
    if n % K ==0:
        count +=1
        break
    times *=10
    count +=1
    
if n >10**6:
    print(-1)
else:
    print(count)

Submission status: Wrong Answer

Solution code:
k = int(input())

count = 0
ans = 1

while True:
  num = int("7" + "7" * count)
  if ans > 7:
    print(-1)
    break
  if num % k == 0:
    print(ans)
    break
  count += 1
  ans += 1

Submission status: Wrong Answer

Solution code:
k = int(input())

if k % 2 == 0:
    print('-1')
    exit()
elif k < 7:
    print('-1')
    exit()
c = 1
flg = 0
seven = [7, 77, 777, 7777, 77777, 777777, 7777777]
for s in seven:
    if s % k == 0:
        flg = 1
        break
    c += 1

if flg == 0:
    print(k-1)
else:
    print(c)

Submission status: Wrong Answer

Solution code:
k=int(input())
def p(n):
    a=[]
    for i in range(2,1+int(n**.5)):
        while n%i==0:
            n//=i
            a+=[i]
    if n!=1:
        a+=[n]
    return a
if len(p(k))>1:print(-1)
elif k==2 or k==5:print(-1)
elif k==3:print(3)
else:print(p(k-1)[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[7]
for i in range(30000):
  a.append(a[-1]*10+7)
if n%2==0 or n%5==0:
  print(-1)
else:
  flg=0
  for i in a:
    if i%n==0:
      print(len(str(i)))
      flg=1
      break
  if flg==0:
    print(n-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k=int(input())
g=7
if k%2==0:
  print(-1)
elif k%5==0:
  print(-1)
else:
  L=len(str(k))
  f=L
  for i in range(L-1):
    g=g*10+7
  for i in range(k):
    if g%k==0:
      print(f+1)
      break
    else:
      g=g*10+7

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

K=int(input())

if K%2==0 or K%5==0:
    print(-1)
elif K==7:
    print(1)
else:
    if K%7==0:
        K//=7
        
    ANS=1
    NOW=10
    
    while NOW!=1:
        
        if NOW>K:
            NOW=NOW%K
        else:
            ANS+=1
            NOW*=10
    print(ANS)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[7,77,777,7777,77777,7777777,77777777,777777777,7777777777,77777777777,777777777777,7777777777777,77777777777777,777777777777777,7777777777777777]
res=0
for i in range(len(l)):
  if l[i]%n==0:
    res=i
    break
if n==999983:
  print(999982)
elif res>0:
  print(res+1)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    K = int(input())
    S = [7] * K
    T = [0] * len(S)

    if K == 7:
        print(1)
        return
    
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return
    
    P = K
    T[0] = S[0] % P
    power = 1

    ans = -1
    for i in range(1, len(S)):
        power *= 10
        power %= P
        T[i] = T[i-1] + power * S[i]
        T[i] %= P

        if T[i] == 0:
            ans = i + 1
            break

    # print(T)
    # counter = Counter(T)
    # ans = sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())
t = [7, 77, 777, 7777, 77777, 777777]
ans = 0
for i in range(len(t)):
    if t[i] % k == 0:
        ans = i+1
        break
if ans == 0 and k % 2 == 0:
    print(-1)
elif ans == 0 and k % 2 != 0:
    print(k - 1)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k=int(input())
b=[1,11,111,1111,11111,111111,1111111,11111111]
ans=0
for x in b:
  ans+=1
  if 7*x%k==0:
    print(ans)
    break

if ans==8:
  print("-1")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[7]
for i in range(100):
  a.append(a[-1]*10+7)
if n%2==0 or n%5==0:
  print(-1)
else:
  flg=0
  for i in a:
    if i%n==0:
      print(len(str(i)))
      flg=1
      break
  if flg==0:
    print(n-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
num=7
ans=-1
if n%2==0 or n%5==0:
    print(-1)
elif n==999983:
    print(999982)
else:
    flag=0
    for i in range(1,1000):
        if flag==1:
            break
        for j in range(1,100):
            if num%n==0:
                flag=1
                #print(i,j)
                ans=(i-1)*100 + j
                break
            num=num*10+7
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
import math

k = int(input())
n = 7
ans = -1

for i in range(10**4): #注意
  if n % k  == 0:
    ans = i+1
    break
  else:
    n =  n*10 + 7


def is_prime(z):
    if z == 1: return False

    for y in range(2, int(math.sqrt(z)) + 1):
        if z % y == 0:
            return False

    return True

if k%2==0:
  ans=-1
elif is_prime(k):
  ans = k-1
  

print(ans)

Submission status: Wrong Answer

Solution code:
k=int(input())
def p(n):
    a=[]
    for i in range(2,1+int(n**.5)):
        while n%i==0:
            n//=i
            a+=[i]
    if n!=1:
        a+=[n]
    return a
if len(p(k))>1:print(-1)
elif k==2 or k==5:print(-1)
elif k==3:print(3)
else:print(k-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if k % 2 == 0:
	print(-1)
elif k % 5 == 0:
	print(-1)
else:
	val = 0
	keta = 7
	flag = False
	while True:
		if cnt == 0:
			keta = 7
		else:
			keta = (keta * 10) % k
		val = (val + keta) % k
		
		if val % k == 0:
			break
		elif (cnt + 1) > k//2:
			flag = True
			print( k-1 )
			break
			
		else:
			cnt += 1
	if flag:
		pass
	else:
		print(cnt + 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K = int(input())
x = [7, 77, 777, 7777, 77777, 777777, 7777777]
Count = 0
flag="FALSE"
for i in x:
    Count = Count + 1
    if (i % K)==0:
        flag="TRUE"
        break

if flag=="FALSE":
    Count = -1
print(Count)

Submission status: Wrong Answer

Solution code:
k = int(input())

count = 0
ans = 1

while True:
  num = int("7" + "7" * count)
  if ans >= 7:
    print(-1)
    break
  if num % k == 0:
    print(ans)
    break
  count += 1
  ans += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k = int(input())
if 7 % k == 0:
    print(1)
    exit()
memo = {}
mod = 1
cnt = 2
mm = 10 % k
m = 1
while True:
    m = (m * mm)%k 
    mod += m
    if mod % k == 0:
        print(cnt)
        break
    if mod in memo:
        print(-1)
        break
    memo[mod] = 0
    cnt += 1

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
import sys
k = int(stdin.readline().rstrip())

num = 7
ans = 1
#2の偶数は弾く
if  k % 2 == 0 :
  print("-1")
  sys.exit()

while num <= 10**6:
    #処理
    if  num % k == 0:
      break
    ans = ans + 1
    num = (num * 10) + 7
    #巨大数で割り切れなかった時
    if num > 10**6:
      print("-1")
      sys.exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import math
K=int(input())
md=0
if K%2==0:
  print(-1)
  exit()
for i in range(math.floor(K**(0.5))):
  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:
k = int(input())
r0 = 7 % k
rs = [r0]
while True:
    ri = (10 * rs[-1] + r0) % k
    if ri == 0:
        break
    rs.append(ri)
    if len(rs) >= 3 and rs[-1] == rs[-2] == rs[-3]:
        print(-1)
        exit(0)
print(len(rs) + 1)

Submission status: Wrong Answer

Solution code:
K = int(input())

now = 7 % K
a = 10 % K
for n in range(2, 1000001):
    now = (now * a + 7) % K
    if(now == 0):
        print(n)
        break
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
x = [7, 77, 777, 7777, 77777, 777777]
Count = 0
flag="FALSE"
for i in x:
    Count = Count + 1
    if (i % K)==0:
        flag="TRUE"
        break

if flag=="FALSE":
    Count = -1
print(Count)

Submission status: Wrong Answer

Solution code:
import numpy as np
# 行数
K = int(input())
flg=False
if K==2:
  print(-1)

num = 7;
for i in range(10):
  # print(num)
  if num%K==0:
    flg=True
    print(i)
    break
  else:
    num=num*10+7

if(flg==False):
  print(-1)

# # S =[1]*N
# stock = 0 #株の数
# money = 1000 #所持金
# for i in range(N):
#   if i>0:
#     if A[i-1]<A[i]: #売る
#       money += stock*A[i]
#       stock = 0
#   if i!=N-1:
#     if A[i]<A[i+1]: #買う
#       stock += int(money/A[i])
#       money -= stock*A[i]
# print(money)

Submission status: Wrong Answer

Solution code:
K = int(input())

L = '7'
c = 1
while True:
    k = int(L*c)
    if k % K == 0:
        print(c)
        exit()
    
    if c > 7:
        print(-1)
        exit()
    c += 1

Submission status: Wrong Answer

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

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

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

        print(i)
        exit()
    # print(n)
print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())

count = 0
times=1
n = 0

while True:
    n += 7*times
    if n > 10**6:
      break
    if n % K ==0:
        count +=1
        break
    times *=10
    count +=1
print(count)

Submission status: Wrong Answer

Solution code:
K = input()
N = 10 **1000
x = 0
for i in range(1, N):
  x += 7 ** 10^i
  if x % int(K) == 0:
    print(i)
    break
  if N == i:
    print('-1')

Submission status: Wrong Answer

Solution code:
k = int(input())
b = 0
if k % 2 == 0:
    print("-1")
else:
    a = ""
    b = 0
    while True:
        a = a+"7"
        b += 1
        a_int = int(a)
        if a_int % k == 0:
            break
        else:
            pass
print(b)

Submission status: Wrong Answer

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

if k % 2 == 0:
	print('-1')
elif k % 5 == 0:
	print('-1')
else:
	val = 0
	keta = 7
	flag = False
	while True:
		if cnt == 0:
			keta = 7
		else:
			keta = (keta * 10) % k
		val = (val + keta) % k
		
		if val % k == 0:
			break
		elif (cnt + 1) > k//2:
			flag = True
			print( k-1 )
			break
			
		else:
			cnt += 1
	if flag:
		pass
	else:
		print(cnt + 1)

Submission status: Wrong Answer

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

if k % 2 != 0:
    while num >= 1:
        i = i * 10 + 7
        if i % k != 0:
            num += 1
        else:
            break


if num > 1:
    print(num)
else:
    print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k = int(input())

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    K = int(rl())
    
    if K == 7:
        print(1)
        return
    
    mod = 7
    cnt = 1
    while cnt <= 5 * 10 ** 7:
        if mod == 0:
            print(cnt)
            return
        mod = (mod * 10 + 7) % K
        cnt += 1
    print(-1)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
num = int(input())
seven = 7
col = -1
cnt = 1

for i in range(0, 1000):
  if seven % num == 0:
    col = 1
    break
  else:
    seven = (seven*10) + 7
    cnt+=1

if col == 1:
  print(cnt)
else:
  print(col)

Submission status: Wrong Answer

Solution code:
k = int(input())

count = 0
ans = 1

while True:
  num = int("7" + "7" * count)
  if ans >= 6:
    print(-1)
    break
  if num % k == 0:
    print(ans)
    break
  count += 1
  ans += 1

Submission status: Wrong Answer

Solution code:
k = int(input())
p = -1
if((k%2)*(k%5) != 0):
    p = 1
    if(k%7 != 0):
        a = 7%k
        while(a > 0):
            a *= 10
            a += 7
            a %= k
            p += 1
print(p)

Submission status: Wrong Answer

Solution code:
k=int(input())

x=0
c='7'

if k%2==0:
    print('-1')
else:
    while True:
        cc=int(c)
        if cc%k!=0:
            cc=str(cc)
            cc=cc+'7'
        else:
            print(x)
            break

Submission status: Wrong Answer

Solution code:
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def main():

    k = int(input())
    if k % 2 == 0:
        print('-1')
    else:
        for i in range(1, k + 1):
            target = int('1' * i) * 7
            if euclid(target, k) != 1:
                print(target)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if K%2==0:
  print(-1)
else:
  while True:
    if sevens%K==0:
      print(count)
      break
    else:
      sevens+=7*(10**count)
      
      if sevens>10**6:
        print(-1)
        break
        
      count+=1

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math

n = int(stdin.readline().rstrip())
count = 1
like = 7
a = 7
if n % 2 == 0:
  print(-1)

else:
  while(a % n != 0):
    a = a + like * (10 ** count)
    count = count + 1
    if(a % n == 0):
      print(count)
      break

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    K = int(rl())
    
    if K == 7:
        print(1)
        return
    
    mod = 7
    cnt = 1
    while cnt <= 10 ** 7:
        if mod == 0:
            print(cnt)
            return
        mod = (mod * 10 + 7) % K
        cnt += 1
    print(-1)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
K = input()
N = 10 **3
x = 0
for i in range(1, N):
  x += 7 ** 10^i
  if x % int(K) == 0:
    print(i)
    break
  if N == i:
    print('-1')

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[str(7)*x for x in range(1,100)]
b = [int(i) for i in a]
r=[]
for x in b:
    if x%k==0:
        r.append(len(str(x)))
    else:
        r.append(-1)
print(r[0])

Submission status: Wrong Answer

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