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:
#create date: 2020-08-02 21:08

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def divisor(n):
    i = 1
    table = [7, ]
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(7*i)
            table.append(n // i)
            table.append((n//i)*7)
        i += 1
    table = set(table)
    return table


def main():
    k = ni()
    
    for i in range(1, 13):
        n = int("1" * i)
        #print(i)
        if k in divisor(n):
            print(i)
            quit()
    print(-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math

k = int(input())

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


ans = 1
n = "7"
for _ in range(math.ceil((k + 1)**0.5) + 10000):
    if int(n) % k == 0:
        print(ans)
        sys.exit()
    else:
        n += "7"
        ans += 1
else:
    print(k - 1)

Submission status: Wrong Answer

Solution code:
lst=['7'*k for k in range(1, 11)]
k=int(input())
i=0
ok=False
for _ in lst:
    p=int(lst[i])
    if p%k==0:
        ok=True
        print(i+1)
        break
    i+=1
    
if ok==False:
    print(-1)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=0
if 7%a==0:b=b+1
if 77%a==0:b=b+1
if 777%a==0:b=b+1
if 7777%a==0:b=b+1
if 77777%a==0:b=b+1
if 777777%a==0:b=b+1
if 0==b: b=-1
print(b)

Submission status: Wrong Answer

Solution code:
k = int(input())
ml = []
a = 7
m = 7
i = 0
while m>0:
  m = a%k
  a = 10*m+7
  i += 1
  if i>k : break
print(i)

Submission status: Wrong Answer

Solution code:
def func(val):
    if val%2==0 or val%5==9:
        return 0
    rem = 1
    p = 1
    k = 1
    while rem%val!=0:
        k+=1
        p = (p*10)%val
        rem = (rem+p)%val
    return k

n = int(input())
a = func(n)
b = 10**18
if n%7==0:
    b = func(n//7)
if a==0 and b!=10**18:
    print(-1)
else:
    print(min(a,b))

Submission status: Wrong Answer

Solution code:
import math as m
t = input()
tt = int(t)
# print(t)
ii = 0
x=1
y=7
while 1:
	if y%tt==0:
		print(x)
		break
	y=y*10
	y=y+7
	x=x+1
	print(x)
	if x>1000000:
		print(-1)
		break

Submission status: Wrong Answer

Solution code:
K = int(input())

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

Submission status: Wrong Answer

Solution code:
k = int(input())

if k%2 == 0:
  print(-1)
  exit()
  
i = 1
n = 7

if n%k == 0:
  print(1)
  exit()

while n < 10**6:
  i += 1
  n = int('1'*i)
  if n%k == 0:
    print(i)
    exit()

print(-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

k = inp()
now = 0
for i in range(k+10000):
    now += pow(10,i+1,k)*7
    now %= k
    if now%k == 0:
        print(i+1)
        quit()
print(-1)

Submission status: Wrong Answer

Solution code:
import sys
import math

k = int(input())

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


ans = 1
n = "7"
for _ in range(math.ceil((k + 1)**0.5)):
    if int(n) % k == 0:
        print(ans)
        sys.exit()
    else:
        n += "7"
        ans += 1
else:
    print(k - 1)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=0
if 7%a==0:b=b+1
if 77%a==0:b=b+1
if 777%a==0:b=b+1
if 7777%a==0:b=b+1
if 77777%a==0:b=b+1
if 777777%a==0:b=b+1
print(b)

Submission status: Wrong Answer

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


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

  dp = [0]*(10**7)
  const = 7 % K
  dp[0] = const
  ten = 1
  for i in range(1, 10**7):
    ten = ten*10 % K
    new = (7*ten) % K
    dp[i] = (new + dp[i-1]) % K
    if dp[i] % K == 0:
      print(i+1)
      # print(dp[:i+2])
      return

  print(-1)


if(__name__ == '__main__'):
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k=int(input())
cnt=1
if k%2==0:
    print(-1)
else:
    keta=10
    tmp=0
    while cnt<=10**6:
        tmp+=pow(keta,cnt-1,k)*7
        if tmp%k==0:
            print(cnt)
            break
        cnt+=1

Submission status: Wrong Answer

Solution code:
import math
x = int(input())
if math.gcd(x, 10) != 1:
	print(-1)
	exit()
phi = x
q = x
l = q	
for i in range(3, int(math.sqrt(l)) + 1, 2):
	if q % i == 0:
		phi //= i
		phi *= (i - 1)
		while q % i == 0:
			q //= i
if q != 1:
	phi //= q
	phi *= (q - 1)
print(phi)

Submission status: Wrong Answer

Solution code:
K = int(input())
sev = "7"
while int(sev) < 2**63-1:
    sev = int(sev)
    if sev % K == 0:
        print(len(str(sev)))
        exit()
    sev = str(sev) + "7"
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
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 = str()
n = int(input())
ans = 0
for i in range(10):
    k += "7"
    s = int(k)
    if n in set(prime_factorize(s)):
        ans = i + 1
        break

if ans == 0:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#

import sys
from math import gcd
input=sys.stdin.readline

def main():
    K=int(input())
    if K%2==0:
        print(-1)
        exit()
    if K==5:
        print(-1)
    s=set()
    r=7%K
    rsum=r
    s.add(r)
    for i in range(10**6):
        if rsum==0:
            print(i+1)
            exit()
        r=(r*10)%K
        if r in s:
            break
        s.add(r)
        rsum=(rsum+r)%K
    print(i*K/gcd(rsum,K))
    
    
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    k = input()
    n = (len(k)-1)*"7"
    for i in range(10**6):
        n = str(n)
        k = int(k)
        n += "7"
        n = int(n)
        if n % k ==0:
            print(len(str(n)))
            exit()
    print((-1))

if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k = int(input())

if k%7 == 0:
  print(1)
elif k%11 == 0:
  print(2)
elif k%37 == 0 or k%3 == 0:
  print(3)
elif k%101 == 0:
  print(4)
elif k%41 == 0 or k%271 == 0:
  print(5)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    cnt = 1
    now_mod10 = 1
    mod10 = 1
    while cnt < K:
        md = 7 * now_mod10
        if md % K == 0:
            return cnt
        mod10 = (mod10 * 10) % K
        now_mod10 = (now_mod10 + mod10) % K
        cnt += 1
    return -1

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

Submission status: Wrong Answer

Solution code:

# coding: utf-8

# In[4]:


import numpy as np


# In[33]:


K = int(input())


# In[34]:


def make_77_7(n):
    return  7*np.sum( np.array([ 10**i for i in range(n) ]) )


# In[35]:


def check_baisu(K):
    a = 0
    step = 1
    while a<=10**6:
        a = make_77_7(step)
        if( a%K == 0 ): return step
        step += 1
    return -1


# In[36]:


print(check_baisu(K))

Submission status: Wrong Answer

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


LIMIT = 10 ** 6


def f(n):
    if n % 2 == 0 or n % 5 == 0:
        return None
    x = 1
    k = 1
    while x != 0:
        x = (x * 10 + 1) % n
        k += 1
    return k


def solve(k):
    if k % 2 == 0 or k % 5 == 0:
        return None
    else:
        return f(k)


def main():
    k = int(input())
    res = solve(k)
    if res is None:
        print(-1)
    else:
        print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# def div(n):
#     ans = []
#     for i in range(1,int(n**(1/2)+2)):
#         if n%i == 0:
#             ans.append(i)
#             ans.append(n//i)
#     ans = set(ans)
#     return ans

k = int(input())
# print(div(k))
a = 1
if k % 2 == 0:
    print(-1)
    exit()
for i in range(1,10**8+2):
    if a%k == 0:
        print(i)
        exit()
    a=a*10+1
    a=a%k
print(-1)
# print(div(k))

Submission status: Wrong Answer

Solution code:
MOD = int(input())

if MOD%2 == 0:
  print(-1)
  exit()
if MOD == 7:
  print(1)
  
  
def mod(n):         
  return n % MOD

def modpow(a, n):   #mod(a**n)を高速で求める
    res = 1  
    digit = len(str(bin(n))) - 2
    for i in range(digit):
      if (n >> i) & 1:
        res *= mod(a)
        res = mod(res)
      a = mod(a**2)
    return mod(res)
  
res = mod(7)
count = 1

while count <= 10**6:
  res += mod(modpow(10, count)*7)
  res = mod(res)
  count += 1
  if res == 0:
    print(count)
    exit()
    
print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(1,9):
    if int('7' * i) >= n:
        if int('7' * i)%n == 0:
            print(i)
            exit()

print("-1")

Submission status: Wrong Answer

Solution code:
k = int(input())
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  k%2==0:
    print(-1)
elif len(prime_factorize(k))==1:
    print(k-1)
else:
    w = 1
    # yaku = prime_factorize(k)
    while True:
        s = "7"*w
        if int(s)%k==0:
            print(w)
            break
        w+=1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	K = inputInt()
	if K % 2 == 0:
		print(-1)
		sys.exit()

	if gcd(K, 7) == 1:
		print(K-1)
		sys.exit()

	targ = ""
	for i in range(90000):
		targ += "7"
		tmp = int(targ)
		if tmp % K == 0:
			print(i+1)
			sys.exit()

	print(-1)

def lcm(a, b):
	g = gcd(a, b)
	return a // g * b

def gcd(a, b):
	if a > b:
		a, b = b, a

	while a > 0:
		a, b = b % a, a
	return b


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import time

k = int(input())

tick = time.time()
idx = 0

while True:
    if time.time() - tick > 1.95:
        ans = -1
        break
    idx += 1
    tgt = int("7" * idx)
    if tgt % k == 0:
        ans = idx
        break

print(ans)

Submission status: Wrong Answer

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

import math

def main():
    k = int(input())
    for i, n in enumerate([7, 77, 777, 7777, 77777, 777777]):
        if (n % k) == 0:
            print(i + 1)
            break
    print(-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k=int(input())

sevens="7"
if k%2==0:
    print(-1)
else:
    for i in range(10000):
        if int(sevens)%k==0:
            print(i+1)
            exit()
        else:
            sevens+="7"
    else:
        print(k-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	K = inputInt()
	if K % 2 == 0:
		print(-1)
		sys.exit()

	if gcd(K, 7) == 1:
		print(K-1)
		sys.exit()

	targ = ""
	for i in range(10000):
		targ += "7"
		tmp = int(targ)
		if tmp % K == 0:
			print(i+1)
			sys.exit()

	print(-1)

def lcm(a, b):
	g = gcd(a, b)
	return a // g * b

def gcd(a, b):
	if a > b:
		a, b = b, a

	while a > 0:
		a, b = b % a, a
	return b


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
k = int(input())

x = 7
e = 10

for i in range(10000000):
    # print(x)
    if x == 0:
        print(i + 1)
        exit()
    x = (x * e + 7) % k

print("-1")

Submission status: Wrong Answer

Solution code:
import math
x = int(input())
if math.gcd(x, 10) != 1:
	print(-1)
	exit()
phi = x
q = x
l = q	
for i in range(3, int(math.sqrt(l)) + 1, 2):
	if q % i == 0:
		phi //= i
		phi *= (i - 1)
		while q % i == 0:
			q //= i
if q != 1:
	phi //= q
	phi *= (q - 1)
for i in range(1, phi + 1):
	if phi % i == 0:
		st = "7" * i
		if int(st) % x == 0:
			print(i)
			exit()

Submission status: Wrong Answer

Solution code:
# def div(n):
#     ans = []
#     for i in range(1,int(n**(1/2)+2)):
#         if n%i == 0:
#             ans.append(i)
#             ans.append(n//i)
#     ans = set(ans)
#     return ans

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k = int(input().strip())
f=-1

for i in range(1,500):
    if ((10**i)-1)*7%(9*k)==0:
        
        f=i
        break
print(f)

Submission status: Wrong Answer

Solution code:
K = int(input())
if K % 2 == 0:
    print(-1)
else:
    mod = K
    t = 7
    for _ in range(K+1):
        t *= 10
        t += 7
        if t % mod == 0:
            print(_+2)
            exit(0)
        else:
            t %= mod
    print(-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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