Problem:


Score : 300 points

Problem Statement

Takahashi loves the number 7 and multiples of K.

Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.)

If the sequence contains no multiples of K, print -1 instead.

Constraints

1 \leq K \leq 10^6

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)

Sample Input 1

101

Sample Output 1

4

None of 7, 77, and 777 is a multiple of 101, but 7777 is.

Sample Input 2

2

Sample Output 2

-1

All elements in the sequence are odd numbers; there are no multiples of 2.

Sample Input 3

999983

Sample Output 3

999982



Sample input:
101


Sample output:
4

Submission status: Accepted

Solution code:
def main():
    K = int(input())
    Sum = 0
    Y = 7
    for i in range(K):
        Sum += Y
        Y = (Y*10)%K    
        if Sum % K == 0:
            print(i+1)
            return
    print(-1)
    return

main()

Submission status: Accepted

Solution code:
K = int(input())

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

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

Submission status: Accepted

Solution code:
import sys
import math

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

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

    print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(-1)

Submission status: Accepted

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

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def isMultiple(s, m):
    tmp = 0
    for i in range(len(s)):
        tmp = (tmp * 10 + int(s[i])) % m
        if tmp == 0:
            return i
    return -1


k = int(readline())
acc = "7" * 50000000
if k % 2 == 0:
    ans = -1
else:

    ans = isMultiple(acc, k)
    if ans != -1:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        return
    a = 1
    b = 0
    h = set()
    for i in range(10**6):
        a = a * 10 % k
        b = (a * 7 + b) % k
        if b == 0:
            print(i + 1)
            break
        if b in h:
            print(-1)
            break
        h.add(b)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(-1)

Submission status: Accepted

Solution code:
k = int(input())

if k%2==0 or k%5==0:
    print('-1')
else:
    from itertools import accumulate
    ac = list(accumulate([7*pow(10, i, k)%k for i in range(999983)]))
    for idx, a in enumerate(ac):
        if a%k == 0:
            print(idx+1)
            break
    else:
        print('-1')

Submission status: Accepted

Solution code:
k = int(input())

a = 7
ans = 1
if k == 1 or k == 7:
    print(1)
    exit()
for i in range(1,10**6+1):
    a += (7*pow(10,i,k))%k
    a %= k
    ans += 1
    if a == 0:
        break
    elif i == 10**6:
        print(-1)
        exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())

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

mod = [pow(10, i, k) for i in range(0, 1000000)]

num = 0
for i in range(0, 1000000):
    num += mod[i]
    if 7 * num % k == 0:
        print(i + 1)
        exit()

print('-1')

Submission status: Accepted

Solution code:
def power_func(a,n,p):
    bi = str(format(n,"b"))#2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res*res) %p
        if bi[i] == "1":
            res = (res*a) %p
    return res



K = int(input())
seven=0

if str(K)[-1] in ['0','2','4','5','6','8']:
    print(-1)

else:
    i=0
    seven_mod=0
    while True:
        i+=1

        seven_mod = (seven_mod + 7%K * power_func(10,i,K))%K
        if seven_mod == 0:
            break

    print(i)

Submission status: Accepted

Solution code:
k = int(input())

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

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

print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  k = int(input())
  kint = 7 % k
  before = 7 % k
  if k == 1 or k == 7:
    print(1)
    exit()
  for i in range(k):
    x = (before * 10) % k
    before = x
    kint += x
    kint = kint % k
    if kint % k == 0:
      print(i + 2)
      exit()
  print(-1)
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
K = int(input())

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

A = 7
ans = 1
while(A < K): #O(6)
    A = A*10 + 7
    ans += 1

while(True):
    #print(A)
    A = A % K #1
    if(ans > K):
        print("-1")
        exit()
    if(A==0): #1
        print(ans)
        exit()
    A = A * 10 + 7 # 1
    ans += 1# 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = input()

if k[-1] in ['0','2','4','5','6','8']:
    print(-1)
else:
    k = int(k)
    i = 1
    x = 7
    while x != 0:
        if x % k == 0:
            break
        else:
            x = (x%k)*10 + 7
            i += 1
    print(i)

Submission status: Accepted

Solution code:
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import random
#####################################
k=int(input())
A=[1]*(10**6+1)
A[0]=7%k
for i in range(1,10**6+1):
    A[i]=(A[i-1]*10)%k
ind=1
sum=A[0]
while(sum!=0 and ind<=10**6):
    if (A[ind]+sum)%k==0:
        ans=ind
        break
    sum=(sum+A[ind])%k
    ind+=1
if k==1 or k==7:
    print(1)
elif ind==10**6+1:
    print(-1)
else:
    print(ans+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n =int(input())
if n%2==0:
    print(-1)
elif n==1 or n==7:
    print(1)
else:
    ans =1
    start = 7
    while True:
        start = ((start%n*10%n)+7)%n
        #start = start%n
        #print(start)
        if start ==0:
            ans+=1
            print(ans)
            break
        if ans>=1000000:
            print(-1)
            break
        ans+=1

Submission status: Accepted

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

ans = 1
X = 1
history = set()
while True:
    if X == 0:
        print(ans)
        exit()
    elif X in history:
        print(-1)
    else:
        ans += 1
        X = (X*10 + 1) % K

Submission status: Accepted

Solution code:

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





if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
K=int(input()) 

S=0
count=-1

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

print(count)

Submission status: Accepted

Solution code:
K=int(input())


if K%2==0 or K%5==0:
    print(-1)
    exit()
elif K==7 or K==1:
    print(1)
else:
    M=7%K
    B=7%K
    for i in range(10**7):
        A=((B*10)%K)
        M+=A
        M%=K
        if M==0:
            print(i+2)
            exit()
        B=A+0
        #print(M,B,i)

Submission status: Accepted

Solution code:
k=int(input())


def get(k):
    ans=7
    i=1
    while True:
        if ans%k==0:
            return i
        ans=(ans*10+7)%k
        i+=1




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

else:
    print(get(k))

Submission status: Accepted

Solution code:
#

import sys
input=sys.stdin.readline

def main():
    K=int(input())
    rsum=0
    r=7
    for i in range(10**6+1):
        rsum=(rsum+r)%K
        r=(r*10)%K
        if rsum==0:
            print(i+1)
            exit()
    print(-1)
    
    
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())

result = 0
count = 0
tmp = K
m = tmp % 10

able = 0

for i in range(1, 10):
    if (m * i) % 10 == 7:
        tmp = K * i
        count += 1
        able = 1
        break

if able == 0:
    result = -1
    tmp = 0

while tmp > 7:
    able = 0
    tmp = tmp // 10
    n = tmp % 10
    for i in range(10):
        if (n + (m * i)) % 10 == 7:
            tmp += K * i
            count += 1
            able = 1
            break
    if able == 0:
        result = -1
        break
if result == -1:
    print(-1)
else:
    print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
K=int(input())

def solve(K):
    f=0
    from collections import defaultdict
    if K==1:
        return 1
    elif K%2==0 or K%5==0:
        return -1
    
    if K%7==0:
        if K==7:
            return 1
        else:
            f=1
            K=K//7

    app = defaultdict(lambda: False)
    broken=False
    for n in range(1,K+1):
        if n==1:
            if f==1:
                amari = 1
            else:
                amari = 7%K
        else:
            if f==1:
                amari = (amari + pow(10,n-1,K) )%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: Accepted

Solution code:
#from functools import lru_cache
import sys
from itertools import product
from itertools import combinations
from functools import reduce

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())

k=int(input())
t=0
m=7%k
md=7%k
for i in range(k+1):
    if m==0:break
    else:
        md=(md*10)%k
        m=(m+md)%k
if i==k: i=-2
print(i+1)

Submission status: Accepted

Solution code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

# def
def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return x

def int_map():
    return map(int,input().split())

def int_list():
    return list(map(int,input().split()))

def print_space(l):
    return print(" ".join([str(x) for x in l]))

# import
import numpy as np



# main code
K = int(input())

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


y = 7%K
x = 7%K

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

print(-1)

Submission status: Accepted

Solution code:
import sys
n = int(input())
if n % 2 == 0 or n % 5 == 0:
  print(-1)
  sys.exit()
p = 7
ans = 1
for i in range(1000000):
  q = p % n
  if q == 0:
    break
  else:
    p = 10 * q + 7
    ans += 1
if q != 0:
  print(-1)
else:
  print(ans)

Submission status: Accepted

Solution code:
K = int(input())
if K % 7 == 0: K //= 7
if K % 2 == 0 or K % 5 == 0: print(-1)
#elif K == 1: print(1)
#elif K % 3 == 0: print(K)
else:
    mod = 0
    for i in range(K):
        mod += pow(10,i,K)
        if mod % K == 0:
             print(i + 1)
             break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

ans = -1
mod = 0

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

print(ans)

Submission status: Accepted

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

print(-1)
exit()

Submission status: Accepted

Solution code:
n=input()
if n%7==0:
    n/=7
def numLen(K): 
      
    # If K is a multiple of 2 or 5 
    if(K % 2 == 0 or K % 5 == 0): 
        return -1
  
    number = 0
  
    len = 1
  
    for len in range (1, K + 1): 
          
        # Instead of generating all possible numbers 
        # 1, 11, 111, 111, ..., K 1's 
        # Take remainder with K 
        number = ( number * 10 + 1 ) % K 
      
        # If number is divisible by k 
        # then remainder will be 0 
        if number == 0: 
            return len
  
    return -1
  
print numLen(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

k = int(input())

r = 7 % k
sum_r = r
if r == 0:
    print(1)
    sys.exit()

for i in range(10**6 + 1):
    r *= 10
    r %= k
    sum_r += r
    sum_r %= k
    if sum_r == 0:
        print(i + 2)
        sys.exit()
print(-1)

Submission status: Accepted

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

d=7%k

ans=1
nanawaruk=d
zyuwaruk=10%k

for i in range(10**6):
    if d==0:
        print(ans)
        exit()
    d=((nanawaruk*zyuwaruk)%k+d)%k
    zyuwaruk*=10
    zyuwaruk%=k
    ans+=1
print(-1)

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

k=int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int( input() )

# a = 7
# for _ in range( 30 ):
#     print( a % k )
#     a = 10 * a + 7

rem_list = []
first_rem = 7 % k
a = 7
cnt = 0
while True:
    r = a % k
    cnt += 1
    if r == 0:
        print( cnt )
        break
    elif cnt > 2 and cnt > k:
        print( -1 )
        break
    else:
        a = ( 10 * r + 7 ) % k

Submission status: Accepted

Solution code:
K = int(input())

# k_keta = len(str(K))
# print(k_keta)

#偶数は弾く
if K % 2 == 0:
    print(-1)
    exit()

r = 0
for i in range(1, 10**6): #何回目のループか
    r = (10 * r + 7) % K
    if r % K == 0:
        print(i)
        break
else:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())
cnt = 1
red = 7
memo = [0]*(10**6+10)
while cnt:
    red = red % k
    if red == 0:
        print(cnt)
        exit()
    if memo[red] == 1:
        print(-1)
        exit()
    memo[red] = 1
    red = red * 10 + 7
    cnt += 1

Submission status: Accepted

Solution code:
K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    if K % 7 == 0:
        K = K // 7
    j = 1
    while True:
        if pow(10, j, K*9) == 1:
            print(j)
            break
        else:
            j += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
AtCoder :: Beginner Contest 174 :: Repsept
https://atcoder.jp/contests/abc174/tasks/abc174_c
"""
import sys


def get_multiplier(d, p):
    for m in range(0, 10):
        if (d * m) % 10 == p:
            return m
    return - 1


def solve(K):
    soln = 0
    t = 0
    d = K % 10
    m = get_multiplier(d, 7)
    if m == -1:
        return -1
    t = t + (K * m)
    while t % 10 == 7:
        t //= 10
        soln += 1
    while(t):
        p = 7 - (t % 10)
        if p < 0:
            p = 17 - (t % 10)
        m = get_multiplier(d, p)
        if m == -1:
            return -1
        t += (m * K)
        while t % 10 == 7:
            t //= 10
            soln += 1
    return soln


def main():
    """Main program."""
    K = int(sys.stdin.readline())
    print(solve(K))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
K = int(input())
ans = [False for _ in range(K)]
num = 0
p = 7%K
for i in range(K+1):
    num += p
    p = (p*10)%K
    if ans[num%K] == False:
        ans[num%K] = True
    else:
        print("-1")
        break
    if num%K == 0:
        print(i+1)
        break

Submission status: Accepted

Solution code:
k = int(input())

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

Submission status: Accepted

Solution code:
K = int(input())

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

Submission status: Accepted

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

solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

K = int(input())

d = [0]*(K+1)

r = 0
ten = 1
while 1:
    r = (r+ten*7)%K
    ten *= 10
    ten %= K
    if r == 0:
        print(sum(d)+1)
        break
    if d[r] != 0:
        print(-1)
        break
    elif d[r] == 0:
        d[r] = 1

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    k = int(input())

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


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """101"""
        output = """4"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """2"""
        output = """-1"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """999983"""
        output = """999982"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

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 = 7
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+7
    a=a%k
print(-1)
# print(div(k))

Submission status: Accepted

Solution code:
K = int(input())
n7 = 7
# もしそのような倍数が存在するとしたらK項よりも必ず少ないというクソみたいな仮定をおいてみる
for i in range(1,10**6+10):
    if n7<K:
        n7 = n7 * 10 + 7
        continue
    m = n7 % K
    if m == 0:
        print(i)
        exit()
    n7=m*10+7
print('-1')

Submission status: Accepted

Solution code:
def main(K):
    lst = [i for i in range(1, 10)]
    K_str = str(K)
    if K_str[-1] in ['0', '2', '4', '5', '6', '8']:
        print(-1)
    else:
        counta = 1
        a = 7
        amari_memo = 70 % K
        while a % K:
            counta += 1
            a = a % K + amari_memo
            amari_memo = amari_memo * 10 % K
        print(counta)


if __name__ == '__main__':
    K = int(input())
    main(K)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	k = int(input())
	#b , c = tin()
	#s = input()
	if k % 2 == 0 or k%5 == 0:
		return -1
	amari = 0
	for i in range(mod*mod):
		amari += 7*pow(10, i, k)
		amari %= k
		if amari == 0:
			return i+1
			
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
import sys;K, = map(int, input().split())

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

Submission status: Accepted

Solution code:
K = int(input())



seed = 0
OK = False
for i in range(K):
    seed = (10*seed +7)%K
    if seed == 0:
        print(i+1)
        OK = True
        break
if not OK:
    print(-1)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(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]
for i in range(K+2):
    A.append((A[-1]*10) % K)

a = 1
i = 1
while True:
    if a % K == 0:
        print(i)
        break
    else:
        a += A[i]
        a %= K
        i += 1

Submission status: Accepted

Solution code:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print(-1)
  exit(0)
MOD = k
n = 0
l = []
root = 1
for i in range(1000000):
  n += 7 * root
  n %= k
  if n == 0:
    print(i + 1)
    exit(0)
  root *= 10
  root %= k
print(-1)

Submission status: Accepted

Solution code:
import sys 
from collections import defaultdict
sys.setrecursionlimit(10**6)
MOD = 10**9+7 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
K = int(readline())
a = defaultdict(int)
cnt = 0
N = 7
while True:
    cnt += 1
    s = N % K
    if s == 0:
        print(cnt)
        sys.exit()
    if s in a:
        print(-1)
        sys.exit()
    a[s] = 1
    N += pow(10,cnt,K)*7 
    N %= K

Submission status: Accepted

Solution code:
#C
K = int(input())
judge=False
num = 7
for i in range(K):
    num = num % K
    #print(num)
    if num == 0:
        print(i+1)
        judge = True
        break
    else:
        num = num*10+7
if judge == False:print("-1")

Submission status: Accepted

Solution code:
K = int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

if K%2 == 0 or K%5 == 0:
    ans = -1
else:
    ans = 1
    mod = 7
    mod_bfr = 7

    while True:
        if mod % K == 0:
            break
        else:
            mod_nxt = mod_bfr * 10
            if mod_nxt < K:
                mod += mod_nxt
                mod_bfr = mod_nxt
            else:
                mod += mod_nxt % K
                mod_bfr = mod_nxt % K
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())
f = 1
j = 7%K
while f < K and j != 0:
  j = (j*10 + 7)%K
  f += 1
if j == 0:
  print(f)
else:
  print('-1')

Submission status: Accepted

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

t  = [0,1,2,3,4,5,6,7,8,9]
tb = [0,7,0,9,0,0,0,1,0,3]

def solve(K: int):
    k =K
    temp = 0
    ct = 0
    b = k%10

    while(True):
        ct+=1
        u = temp%10
        p = -1
        for i in range(10):
            if (u + (b*i)) %10 == 7:
                p = i
                break
        if p == -1:
            print(-1)
            return
        temp += k*p
        if temp == 7:
            print(ct)
            return
        temp //= 10

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
K=int(input())

SUM=0
for i in range(10**6+5):
  SUM += 7*pow(10,i,K)
  SUM %= K
  if SUM==0:
    print(1+i)
    exit()
  
print(-1)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

K = I()

d = defaultdict(int)
digit = 1
val = 7%K
while True:
    if val == 0:
        print(digit)
        exit()
    else:
        if d[val]:
            print(-1)
            exit()
        d[val] += 1
        digit += 1
        val = 10*val+7
        val %= K

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    K = ii()
    if K%2==0 or K%5==0:
        print(-1)
        return
    a = 7
    cnt = 1
    while a%K != 0:
        a = (10*a+7)%K
        cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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


def solve():
    K = int(rl())
    
    mods = [7 % K]
    for _ in range(10 ** 6):
        if mods[-1] == 0:
            print(len(mods))
            return
        mods.append((mods[-1] * 10 + 7) % K)
    print(-1)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
K=int(input())

tmp=7

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

print('-1')

Submission status: Accepted

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