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: Runtime Error

Solution code:
def main():
    K = int(input())
    Kstr = str(K)
    
    if Kstr[-1] in ('0','2','4','6','8','5'):
        print(-1)
    else:
        if K%7 == 0:
            L = (9*K)/7
        else:
            L = 9*K
        S = 10
        for i in range(1,L):
            S = S%L
            if S == 1:
                print(i)
                break
            S = S*10
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k = int(input())
if k % 7 == 0:
    L = (9 * k) / 7
else:
    L = 9 * k
    
if L % 2 == 0 or L % 5 == 0:
  print(-1)

i = 1
while True:
    if 10**i % L == 1:
        break
    else:
        i += 1
print(i)

Submission status: Runtime Error

Solution code:
i = 0;
mod = 0;
while True:
    mod = (mod*10 + 7) % k;
    if mod == 0:
        break;
    i += 1;
    if i == k:
        j = -2
        break;

print(i+1)

Submission status: Runtime Error

Solution code:
k = int(input())
if k % 7 == 0:
    L = (9 * k) / 7
else:
    L = 9 * k
i = 1
while True:
    if 10**i % L == 1:
        break
    else:
        i += 1
    if i % 1000 == 0:
        print(i)
print(i)

Submission status: Runtime Error

Solution code:
K = int(input())
a = ""
ans = 0
amari = 10

if K%2 == 0:
    print(-1)
elif K%5 == 0:
    print(-1)
elif K%7 == 0:
    L = 9*K//7
else:
    L = 9*K

for p in range(10**6):
    if amari % L == 1:
        print(p+1)
        break
    else:
        amari = (amari*10)%L

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    import sys
    
    input = sys.stdin.readline

    K = int(input())
    res = 7

    if K % 2:
        while res < 10 ** 7:
            cal = func(K, res)
            k = str(cal)
            if k.count('7') == len(k):
                print(len(k))
                break
            res += 7
        else:
            print('-1')
    else:
        print('-1')


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np


K=int(input())
num=len(str(K))
start=7
count=0
last=int(str(K)[-1])
li=[1,3,7,9]

if last not in li:
    print(-1)
    exit()
else:
    while(True):
        if start%K==0:
            break
        else:
            start=start*10+7
            count+=1
print(count)

#Kの倍数が7だけで表現できるのか？？？
#777777>Kという状況でなければ倍数は入りえない
#7は無限に伸ばせてしまう
#どこまで探索すればよいのか？？？Kの
#まず、-1になる条件は、7が末尾につかないこと=偶数
#中には奇数しかない。Kも奇数でしかありえない
#末尾5も削除。末尾1,3,7,9は候補に入る
#奇数、1,3,7だけで構成、素数、が候補になりうる
"""
1,7
1,7,11,77
1, 3, 7, 21=3,7, 37, 111=3,37,259=7,37, 777#
1, 7, 11, 77, 101, 707, 1111, 7777
1, 7, 41, 271, 287, 1897, 11111, 77777

1, 3, 7, 11, 13, 21, 33, 37, 39, 49, 77, 91, 111, 
143, 147, 231, 259, 273, 407, 429, 481, 539, 637, 
777, 1001, 1221, 1443, 1617, 1813, 1911, 2849, 3003, 
3367, 5291, 5439, 7007, 8547, 10101, 15873, 19943, 21021, 
23569, 37037, 59829, 70707, 111111, 259259, 777777
#末尾が
"""
"""
if K%2==0:
    print(-1)
    exit()



while(True):
    li=make_divisors(K)
    for i in li:
        if i >=K and i%K==0:
            print(num)
    num+=1
    if num>=7:
        print(-1)
"""

Submission status: Runtime Error

Solution code:
N,Q = map(int,input().split())
list_c = [int(a) for a in input().split()]

List=[list(map(int,input().split())) for x in range(Q)]

for i in range(Q):
    l = List[i][0]
    r = List[i][1]
    list_c_new = list_c[l-1:r]
    set_list = set(list_c_new)
    print(len(set_list))

Submission status: Runtime Error

Solution code:
K = int(input())

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

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

Submission status: Runtime Error

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

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

A = [1]  # A[i] = 10**i mod K
for i in range(K-2):
    A.append((A[-1]*10) % K)

s = A[0]
for i in range(1,K):
    if s % K == 0:
        print(i)
        exit()
    else:
        s += A[i]
        s %= K

Submission status: Runtime Error

Solution code:
K = int(input())

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

int main(){
    int n;
    cin>>n;
    int len=to_string(n).length();
    if(n%2==0 || n%5==0){
        cout<<"-1\n";
    }
    int k=7;
    int cnt=1;
    while(true){
        if(k%n==0){
            cout<<cnt<<"\n";
            break;
        }
        else if(cnt>n){
            cout<<"-1\n";
            break;
        }
        k=(k%n)*10+7;
        cnt++;
    }
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k = int(input())
ok = [0]*k
x=7 % k
ok[x] = 1
if x == 0:
  print(1)
else:
  now = 1
  while now+=1:
    x = (x*10 +7) % k
    if ok[x] == 1:
      print(-1)
      break
    elif x == 0:
      print(now)
      break

Submission status: Runtime Error

Solution code:
k = int(input())
ok = [0]*k
x=7 % k
ok[x] = 1
if x == 0:
  print(1)
else:
  now = 1
  while now+=1:
    x = x*10 +7
    if ok[x] == 1:
      print(-1)
      break
    elif x == 0:
      print(now)
      break

Submission status: Runtime Error

Solution code:
k = int(input())

#-1を出力する実装はまだしてない
nana = 0
for i in range(10**6):
    if (nana*i % k == 0:
        print(i+1)
        break
    else:
        nana += "7"

Submission status: Runtime Error

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

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


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

Submission status: Runtime Error

Solution code:
n = int(input())
a = [7]*(n)
t = set()
for i in range(1,n):
    a[i] += a[i-1]*10
    a[i]%=n
for i in range(n):
    if(a[i] in t):
        print(len(t))
        exit()
    t.add(a[i])
if(k==1 or 7):
    print(1)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
N = int(input())
# N = 999983
import math
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
if (N==2)|(N==5)|(is_prime(N)==False):print(-1)
else:
    a = 7
    for i in range(1,10**6):
        if a%N == 0:
            print(n)
            break
        a += 7*10**i

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k=int(input())
x=7%k
y=9%k
z=10%k

for i in range(1:k):
    if (x/y)*((z**(i)-1))%k==0:
        break

if (7/9)*((10**(i)-1))%k==0:
    print(i)
else:
     print("-1")

Submission status: Runtime Error

Solution code:
k = int(input())
ans = 0
now = 7
while True:
    ans += 1
    now %= k
    if now == 0:
        print(ans)
        exit(-1)
    now = now * 10 + 7
    if ans == 1000000:
        print(-1)
        exit(-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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)
    print(remainders)
    if sum(remainders) % k == 0:
        print(counter)
        sys.exit()

Submission status: Runtime Error

Solution code:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print(-1)
else:
  mystr = '7'
  while True:
    if int(mystr, 10) % k == 0:
      print(len(mystr))
      break
	else:
      mystr += '7'

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
def sevens(r):
    return ((70*10**(r-1)/9)-(7/9))

a = 0
i = 1
n = int(input())
if(n % 2 == 0):
  print("-1")
else:
  while True:
    a = sevens(i)
    if(a % n == 0):
        break
    i += 1
 
print(i)

Submission status: Runtime Error

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):
            ans=i+1
            break
        seven=(seven*10+7)%K
    
    print(ans)

Submission status: Runtime Error

Solution code:
k=int(input())
x=7%k
y=9%k
z=10

for i in range(1000000):
    z=z%k
    if (x/y)*((z-1))%k==0:
        break
    z=z*(10%k)

if (7/9)*((10**(i+1)-1))%k==0:
    print(i+1)
else:
     print("-1")

Submission status: Runtime Error

Solution code:
ans = -1
if K in [2,5]:
    pass
else:
    num = 7
    ans = 0
    while True:
        ans += 1
        if num % K == 0:
            break
        else:
            num = (num * 10 + 7)%K
print(ans)

Submission status: Runtime Error

Solution code:
k=int(input())
x=7%k
y=9%k
z=10

for i in range(10000000):
    z=z%k
    if (x/y)*((z-1))%k==0:
        break
    z=z*10

if (7/9)*((10**(i+1)-1))%k==0:
    print(i+1)
else:
     print("-1")

Submission status: Runtime Error

Solution code:
k=int(input())
x=7%k
y=9%k
z=10%k

for i in range(100):
  	z=z%7
    if (x/y)*((z-1))%k==0:
        break
    z=z*10

if (7/9)*((10**(i+1)-1))%k==0:
    print(i+1)
else:
     print("-1")

Submission status: Runtime Error

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

Submission status: Runtime Error

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(i)
        break
    ans += 1
    num = num * 10 + 7
print(ans)

Submission status: Runtime Error

Solution code:
import math

def isPrime(num):
    for i in range(2, math.sqrt(num) + 1):
        if num % i == 0:
            return False
    return True

seven = 7
cnt = 0
num = int(input())
for i in range(1000):
    if seven % num == 0:
        print(cnt)
        quit()
    seven *= 10
    seven += 7
    cnt += 1
if isPrime(num):
    print(num -1)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
#from functools import lru_cache
import sys
import math
def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

ls = rvfunc(int)(reader())
n,k=ls[0]
a=ls[1]

def reqk(num):
    return sum(vfunc(lambda aa:math.ceil(aa/float(num))-1)(a))
def binary_search(imin=None,imax=None):
    if [imin,imax]==[None]*2: imin,imax=0,10**9
    if (imax < imin):
        return imin
    else:
        imid = int(imin + (imax - imin) / 2)
        if (reqk(imid)<k):return binary_search(imin, imid - 1)
        elif (reqk(imid)>k):return binary_search(imid + 1, imax)
        else:return imid
print(binary_search() if k!=0 else max(a))

Submission status: Runtime Error

Solution code:
k = int(input())

if k % 2 == 0:
  print(-1)
else:
  t = 7
  kai = 1
  while(True):
  	if t % k == 0:
      print(kai)
      break
    else:
      kai += 1
      t += 7*(10**kai)

Submission status: Runtime Error

Solution code:
import math

def isPrime(num):
    for i in range(2, math.sqrt(num) + 1):
        if num % i == 0
            return False
    return True

seven = 7
cnt = 0
num = int(input())
for i in range(1000):
    if seven % num == 0:
        print(cnt)
        quit()
    seven *= 10
    seven += 7
if isPrime(num):
    print(num -1)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import math
import time
import numpy as np

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

k = int(input())


a = prime_factorize(k)

def nana(n):
    for i in range(1,100000):
        na = int("7"*i)
        if na % n ==0:
            return i

if k %2 == 0:
    print(-1)
else:
    t = []
    for e in a:
        t.append(nana(e))
    print(np.gcd.reduce(t))

Submission status: Runtime Error

Solution code:
a=int(input())
b=int("7"*a)
c=int("7"*(a-1))
if b%a==0:
  print(a)
elif c%a==0:
  print(a-1)
else:
  print(-1)

Submission status: Runtime Error

Solution code:
#from functools import lru_cache
import sys
import math
def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

ls = rvfunc(int)(reader())
n,k=ls[0]
a=ls[1]

def reqk(num):
    return sum(vfunc(lambda aa:(math.ceil(aa/float(num))-1) if math.ceil(aa/float(num))!= 0 else 0)(a))
def binary_search(imin=None,imax=None):
    if [imin,imax]==[None]*2: imin,imax=0,10**9
    if (imax < imin):
        return imin
    else:
        imid = int(imin + (imax - imin) / 2)
        if (reqk(imid)<k):return binary_search(imin, imid - 1)
        elif (reqk(imid)>k):return binary_search(imid + 1, imax)
        else:return imid
print(binary_search() if k!=0 else max(a))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# 整数の入力
k = int(input())

if k % 2 == 0:
    print(-1)
    #print("a")
    exit(0)

d1 = k % 10
print(d1)
if d1 != 1 and d1 != 7 and d1 != 3 and d1 != 9:
    print(-1)
    #print("b")
    exit(0)

def PrimeJudge(n):
    ret = True
    for i in range(2, int(n ** 0.5)+1):
        if n % i == 0:
            ret = False
            break
    return ret

if PrimeJudge(k) == False:
    print(-1)
    #print("c")
    exit(0)

s = 7
while(1):
    i = int(s)
    if i < k:
        s = str(s)+'7'
    else:
        if i % k == 0:
            print(len(s))
            exit(0)
        else:
            s = str(s)+'7'

Submission status: Runtime Error

Solution code:
a = int(input())

def one_cry_def(a, c):

    if str(a).count('7') == len(str(s)):
        return len(str(s))
        
        
    one_cry = int(str(a)[len(str(a))-1])
    if one_cry == 1:
        init = 7
    elif one_cry == 3:
        init = 9
    elif one_cry == 9:
        init = 3
    else:
        init = 1

    one_cry_def(int((a * init - 7) / 10))
    



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

    
else:
    
    result = 0
    kotae = one_cry_def(a, result)
    print(kotae)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k = int(input())
p = []
for i in range(100000000):
  p.append(7)
  p = map(str,p)
  d = ''.join(map(str,p))
  int(d)
  if d % k == 0:
    break
print(len(d))

Submission status: Runtime Error

Solution code:
#C
K=int(input())
flag=[True for i in range(K)]
se=0
for i in range(len(str(K))):
    se+=7*(10**i)

if se<K:
    R=se
    st=len(str(K))
else:
    st=len(str(K))-1
    R=se-7*(10**st)

flag[R]=False
while True:
    if R==0:
        ans=st
        break
    elif K%2==0:
        ans==-1
        break

    R+=7*pow(10,st,K)
    R%=K
    st+=1
print(ans)

Submission status: Runtime Error

Solution code:
K = int(input())

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


def factorization(n):
    arr = []
    temp = n
    for i in range(3, n, 2):
        if i * i > n:
            break
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr


arr = factorization(K)
# print(f'{arr=}')

ans = 1
for a in arr:
    b = a[0]
    time = a[1]
    # print(f'{K=}')
    v = ''
    M = set([])
    for i in range(1, 999982):
        v += '7'
        mod = int(v) % b
        if mod == 0:
            # print(f'{K=}, {i=}')
            ans *= i**time
            break
        if mod in M:
            print(f'{K=}, i=-1')
            print(-1)
            exit()
        M.add(mod)

print(ans)

Submission status: Runtime Error

Solution code:
K = int(input())
ans = 1
X = 7
cnt = K
while(cnt > 0):
#     print('rem={}'.format(X%K))
    rem = X % K
    if rem == 0:
        print(ans)
        break
    else:
        remlst.append(rem)
        ans += 1
        X = rem*10 + 7 
        cnt -= 1

if rem != 0:
    print(-1)

Submission status: Runtime Error

Solution code:
k = int(input())

import fractions

flag = False

for i in range(n):
    f = fractions.gcd(k,(10**n-1)/9*7)
    if f == k:
        flag = True
        break

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import deque
mod = 10**5
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

k = input()
K = int(k)

if(K%2==0 or K%5==0):
  print("-1")
  exit()
  
a = ["7"]*(K-1)
num = "".join(a)
num = int(num)
if(num % K == 0):
  print(K-1)
  exit()
  
count = len(k)
a = ["7"]*(count)
num = "".join(a)
num = int(num)
flag = 0
while count < mod:
  if(num%K==0):
    flag = 1
    break
  num += 7*(10**count)
  count += 1
if(flag == 1):
  print(count)
else:
  a = ["7"]*(K-1)
  num = "".join(a)
  num = int(num)
  if(num % K == 0):
    print(K-1)
  else:
    print("-1")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import math
import time
import numpy as np

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

k = int(input())

a = prime_factorize(k)

def nana(n):
    for i in range(1,100000):
        na = int("7"*i)
        if na % n ==0:
            return i

t = []
for e in a:
    t.append(nana(e))
print(np.gcd.reduce(t))

Submission status: Runtime Error

Solution code:
k = input()

if int(str(k)[-1]) % 2 or int(str(k)[-2]) % 5:
  print(-1)

Submission status: Runtime Error

Solution code:
k=int(input())
x=7%k
y=9%k
z=10%k

for i in range(100):
    if (x/y)*((z**(i+1)-1))%k==0:
        break

if (7/9)*((10**(i+1)-1))%k==0:
    print(i+1)
else:
     print("-1")

Submission status: Runtime Error

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

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 seven(n):
    return int("".join(list(map(str,[7 for j in range(n)]))))

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 make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

k = int(input())
if k%7 == 0:
    k /= 7

if k == 1:
    print("1")
elif k == 3:
    print("3")
elif k%2 == 0:
    print("-1")
elif k%5 == 0:
    print("-1")
else:
    fact = prime_factorize(k)
    if len(fact) == 1:
        ans = 0
        for i in make_divisors(k-1):
            if seven(i)%k == 0:
                if ans == 0:
                    ans = i
                else:
                    ans = min(ans,i)
        print(ans)
    else:
        c = collections.Counter(fact)
        fact = [[c.keys(),c.values(),0] for i in range(len(fact))]
        for i in fact:
            ans = 0
            for j in make_divisors(i[0]-1):
                if seven(i)%i == 0:
                    if ans == 0:
                        ans = i
                    else:
                        ans = min(ans,i)
            i[2] = ans
        unchi = [fact[i][2] for i in range(len(fact))]
        print(lcm_list(unchi))

Submission status: Runtime Error

Solution code:
a=int(input())
b="7"*a
c="7"*(a-1)
if b%a==0:
  print(a)
elif c%a==0:
  print(a-1)
else:
  print(-1)

Submission status: Runtime Error

Solution code:
k=int(input())
x=7%k
y=9%k
z=10%k

for i in range(10000000):
    if (x/y)*((z**(i+1)-1))%k==0:
        break

if (7/9)*((10**(i+1)-1))%k==0:
    print(i+1)
else:
     print("-1")

Submission status: Runtime Error

Solution code:
K=int(input())

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

i=1
seven = [7]
s_append = seven.append

while seven.join()/K!=seven.join()//K:
  s_append(7)
  i += 1

print(i)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

pn=factorization(k)

go =0
keta = len(str(k))
sevens = []

if k % 2 == 0 or k %5 == 0:
    print(-1)
    break
elif str(k)[-1] == "3":
    for i in range(9,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "7":
    for i in range(1,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "9":
    for i in range(3,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "1":
    for i in range(7,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))

Submission status: Runtime Error

Solution code:
k = input()

if int(str(k)[-1]) % 2 OR int(str(k)[-2]) % 5:
  print(-1)

Submission status: Runtime Error

Solution code:
K = int(input())

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

K_string = str(K)
K_length = len(K_str)

for i in range(K_len, K):
    num_str = '7' * i
    num = int(num_str)
    if num % K == 0:
        print(i)
        exit()

print(-1)

Submission status: Runtime Error

Solution code:
K = int(input())


def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list



    
if K % 2 == 0 or K % 5 == 0:
    ans = -1
else:
    for x in make_divisor_list(K-1):
        if int("7"*x) % K == 0:
            ans = x

            break
print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

pn=factorization(k)

go =0
keta = len(str(k))
sevens = []

if k % 2 == 0 or k %5 == 0:
    print(-1)
    break
elif str(k)[-1] == "3":
    for i in range(9,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i))
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "7":
    for i in range(1,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i))
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "9":
    for i in range(3,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i))
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "1":
    for i in range(7,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i))
            continue
        else:
            print(str(k * i).count('7'))

Submission status: Runtime Error

Solution code:
k = int(input())
while True: 
    if 7*int('1'*i) / k > k: 
        print(-1)
        break
    elif str(7*int('1'*i)/k)[-2:] != '.0':
        i +=1
    else: 
        print(i)
        break

Submission status: Runtime Error

Solution code:
K = int(input())
ans = 1
X = 7
cnt = K
while(cnt > 0):
#     print('rem={}'.format(X%K))
    rem = X % K
    if rem == 0:
        print(ans)
        break
    else:
        remlst.append(rem)
        ans += 1
        X = rem*10 + 7 
        cnt -= 1

if cnt == 0:
    print(-1)

Submission status: Runtime Error

Solution code:
K = int(input())

for i in range(1, 10):
    if str(K*i)[-1] == "7":
        S = ""
        ans = 0
        while ans <= 100000:
            S += "7"
            ans += 1
            if int(S)%K == 0:
                Flag = True
                break

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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