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:

K = int(input())
ans=-1
sevens=[7,]
for i in range(1, K+1):
    sevens.append((10*sevens[i-1]+7)%K)
    if sevens[i-1]%K==0:
        ans=i
        print(ans)
        exit()
print(ans)

Submission status: Accepted

Solution code:
k=int(input())
num=0
for i in range(0,k+1):
    num=(num*10+7)%k
    if num==0:
        print(i+1,'\n')
        break
if num:
    print("-1\n")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(K):
    K_one = K % 10
    cnt = 0

    carry = 0
    carry_one = carry % 10

    while True:
        is_ok = False
        for i in range(0,9+1):
            if (i * K_one + carry_one) % 10 == 7:
                is_ok = True
                cnt += 1
                carry = (K * i + carry) // 10
                carry_one = carry % 10
                break
        
        if not is_ok:
            print(-1)
            return
        
        if carry == 0:
            print(cnt)
            return

        carry_str = str(carry)
        if carry_str.count('7') == len(carry_str):
            print(len(carry_str) + cnt)
            return
    
if __name__ == '__main__':
    K = int(input())
    solve(K)

Submission status: Accepted

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

    check_list = set()
    check = 7 % K
    res = 1
    while check % K != 0:
        check = 10*check + 7
        check %= K
        res += 1
        if check not in check_list:
            check_list.add(check)
        else:
            print(-1)
            exit()
    print(res)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def calc(K):
    if K % 2 == 0:
        print(-1)
        return
    elif 7 % K == 0:
        print(1)
        return

    a = [7 % K]
    for x in range(1, K):
        cur = (a[x-1]*10+7) % K
        if cur == 0:
            print(x + 1)
            return
        else:
            a.append(cur)

    print(-1)


K = int(input())

calc(K)

Submission status: Accepted

Solution code:
K = int(input())

a = [0] * 1000001
a[0] = 7 % K
for i in range(1000000):
    a[i+1] = (a[i] * 10 + 7) % K 
    
    if (a[i] == 0):
        break

if(i == 999999):
    print('-1')
else:
    print(i+1)

Submission status: Accepted

Solution code:
K = int(input())
a = [7%K]
for i in range(1,K):
    a.append((10*a[i-1]+7)%K)

ans = -1
for i in range(K):
    if a[i] == 0:
        ans = i+1
        break

print(ans)

Submission status: Accepted

Solution code:
K = int(input())

a = []
cnt = 0

# a[0] = [7 % K]
a.append(7 % K)

for i in range(K):
    # a[i+1] = [(a[i]*10 + 7) % K]
    a.append((a[i]*10 + 7) % K)

for j in range(K):
    if a[j] == 0:
        cnt = 1
        break

if cnt == 0:
    print('-1')
else:
    print(j+1)

Submission status: Accepted

Solution code:
K=int(input())
ans=[0]*K
rem=7
for i in range(K):
    rem=rem%K
    if rem == 0:
        print(i+1)
        exit()
    else :
        if ans[rem]==1:
            print(-1)
            exit()
        else:ans[rem]=1
        rem=10*rem+7

Submission status: Accepted

Solution code:
K = int(input())
N=7
A = 1


def f(A, L):
    if L % 2 == 0 or L % 5 == 0:
        A = -1
    else:
        x = 10
        b = 0
        while b == 0:
            if x % L == 1:
                break
            else:
                x = (x * 10) % L
                A += 1
    return A


if K % 7 == 0:
    L = 9*K/7
    A = f(A, L)
else:
    L = 9*K
    A = f(A, L)

print(A)

Submission status: Accepted

Solution code:
k = int(input())
if k % 2 == 0 or k % 5 == 0:
  print(-1)
else:
  if k % 7 == 0:
    k /= 7
  m = 1
  m2 = 1
  c = 1
  while m % k != 0:
    m2 = (m2*10)%k
    m = (m+m2)%k
    c += 1
  print(c)

Submission status: Accepted

Solution code:
K = int(input())
ans = 1
dp = [-1] * K
num = 7
while True:
    num = num % K
    if dp[num % K] != -1:
        print(-1)
        break
    elif num % K == 0:
        print(ans)
        break
    else:
        dp[num % K] = 1
    ans += 1
    num = num * 10 + 7

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()


if n % 7 == 0:
    n //= 7
    n *= 9
    if n % 2 and n % 5:
        co = 1
        i = 0
        while True:
            i += 1
            co *= 10
            co %= n
            if co == 1:
                break
        print(i)
    else:
        print(-1)
else:
    n *= 9
    if n % 2 and n % 5:
        co = 1
        i = 0
        while True:
            i += 1
            co *= 10
            co %= n
            if co == 1:
                break
        print(i)


    else:
        print(-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


def solve():
    K = input()

    ans = len(K)
    K = int(K)
    x = int("7" * ans)

    use = set()
    while 1:
        if x % K == 0:
            break
        x = (x % K) * 10 + 7

        if x in use:
            print(-1)
            return 
        use.add(x)
        ans += 1

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    A = [0 for i in range(k)]
    m = 7%k
    M = 7%k
    cnt = 1
    while  True:
        if A[m] != 0:
            print(-1)
            return
        else:
            if m==0:
                print(cnt)
                return
            else:
                cnt += 1
                A[m] = 1
                M = M*10 % k
                m = (M+m) % k

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# import itertools
# import math
# import sys
# import numpy as np

K = int(input())
# S = input()
# n, *a = map(int, open(0))
# H, W, K = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# S = input()

# d = sorted(d.items(), key=lambda x:x[0])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

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

print(i + 1)

Submission status: Accepted

Solution code:
K = int(input())
a = [7 % K]
for i in range(1, K+1):
    a.append((a[i-1]*10 + 7) % K)
flag = True
for i in range(len(a)):
    if a[i] == 0:
        print(i+1)
        flag = False
        break
if flag:
    print(-1)

Submission status: Accepted

Solution code:
k = int(input())

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

a=7
c=1
while 1:
    if a%k==0 :
        break
    a=(a*10+7)%k
    c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    buf = {}
    K = iRaw()
    tmp = 7%K
    buf[tmp]=1
    idx = 1
    while True:
        if tmp == 0:
            print(idx)
            return
        idx+=1
        tmp = (tmp*10+7)%K
        if tmp in buf:
            print(-1)
            return
        buf[tmp]=1

main()

Submission status: Accepted

Solution code:
K = int(input())

cnt = 0
a = 0
ans = False

for i in range(K):
    a = 10 * a +7
    cnt += 1
    if a % K == 0 :
        print(cnt)
        ans = True
        break
    else:
        a = a % K

if ans == False:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
## necessary imports

import sys
input = sys.stdin.readline
from bisect import bisect_left;
from bisect import bisect_right;
from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1;
    return x;
    
# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
    if(k > n - k): 
        k = n - k; 
    res = 1;
    for i in range(k): 
        res = res * (n - i);
        res = res / (i + 1); 
    return int(res);

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;


# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret;
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################


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

Submission status: Accepted

Solution code:
## necessary imports

import sys
input = sys.stdin.readline
from bisect import bisect_left;
from bisect import bisect_right;
from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1;
    return x;
    
# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## nCr function efficient using Binomial Cofficient
def nCr(n, k): 
    if(k > n - k): 
        k = n - k; 
    res = 1;
    for i in range(k): 
        res = res * (n - i);
        res = res / (i + 1); 
    return int(res);

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p): 
    res = 1
    x = x % p  
    if (x == 0) : 
        return 0
    while (y > 0) : 
        if ((y & 1) == 1) : 
            res = (res * x) % p 
        y = y >> 1      
        x = (x * x) % p 
    return res 

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];
    
    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;


# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n): 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret;
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################


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

Submission status: Accepted

Solution code:
from itertools import *
from math import gcd

k = int(input())
if gcd(k, 10) == 1:
    i = 0
    r = 0
    while True:
        i += 1
        r = (10*r+7)%k
        if r == 0:
            print(i)
            break
else:
    print(-1)

Submission status: Accepted

Solution code:
K=int(input())
a=-1
b=0

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

print(a)

Submission status: Accepted

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

K = int(input())
MAX = 1000001
a = []
a.append(7 % K)
for i in range(1,K):
    a.append((a[i-1] * 10 + 7) % K)

for i in range(len(a)):
    if a[i] == 0:
        print(i+1)
        exit(0)

print(-1)

Submission status: Accepted

Solution code:
k=int(input())

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

ans=1
num=7%k

while num!=0:
  num=(10*num+7)%k
  ans+=1

print(ans)

Submission status: Accepted

Solution code:
K = int(input())
a = [7%K]
for i in range(1, K):
  a.append((a[i-1]*10+7)%K)

isCorrect = False
for i in range(K):
  if a[i] == 0:
    print(i+1)
    isCorrect = True
    break
if not isCorrect:
  print("-1")

Submission status: Accepted

Solution code:
K = eval(input())
myNumber = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K = int(input())

a = [0]*(K+1)
a[0] = 7%K
ans = -1
for i in range(K):
    if(a[i]==0):
        ans = i+1
        break
    a[i+1] = (10*a[i]+7)%K
print(ans)

Submission status: Accepted

Solution code:
def main():
    k = int(input())
    amari = 7
    ans = 0

    while ans <= k:
        amari = amari % k
        ans += 1
        if amari == 0:
            print(ans)
            exit()
        else:
            amari = amari * 10 + 7
            #print(amari, ans)
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
K = int(input())

N = 0
count = -1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
K=int(input())
ans=-1
num=0
for i in range(K):
    # num += 7*(10**i)
    # if num % K == 0:
    #ってすると計算量がやばいので
    num = (10*num+7) % K
    if num == 0:
        ans = i+1
        break
print(ans)

Submission status: Accepted

Solution code:
import sys

k=int(input())
mae=0

for i in range(10**6+1):
  now=(10*mae+7)
  if now%k==0:
    print(i+1)
    sys.exit()
  mae=now%k

print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Cyclic mod calculation renshuu

# kの倍数 -> N % k == 0 を探索する
# N%k の値は高々 k種類となる。k回のループで十分に網羅できる。
# kは10**6。制約上も問題がない。
k=int(input())
n=7%k
for i in range(1,k+1):
  if n==0:
    print(i)
    exit()
  # 計算量を抑えてmodするため、漸化式のような実装にすることがミソ。
  n=(n*10+7)%k 
print(-1)

Submission status: Accepted

Solution code:
K= int(input())

if K%2==0:
    print('-1')
else:
    t=True
    n=1
    a=7
    
    while t:
        if n>K:
            t=False
            print('-1')
        if a%K!=0:
            a=(10*a+7)%K
            n+=1
        else:
            t=False
            print(n)

Submission status: Accepted

Solution code:
K=int(input())
s=0

for _ in range(K):
    s=(10*s+7)%K
    if s==0:
        print(_+1)
        exit()
        
print(-1)

Submission status: Accepted

Solution code:
K = int(input())
mod = 0
Good = True
for k in range(K):
    mod = (mod * 10 + 7) % K
    if mod == 0:
        print(k+1)
        Good = False
        break
if Good:
    print(-1)

Submission status: Accepted

Solution code:
K=int(input())

a=7 #第1項
b=10
i=0 #index

if (K%7 == 0):
    L = 9*K/7
else:
    L = 9*K
    
if (L%2==0 or L%5==0):
    print(-1)
else:
    while(i<=L):
        if (b%L==1):
            break
        else:
            b=10*(b%L)
            i += 1
    print(i+1)

Submission status: Accepted

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

Submission status: Accepted

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

k = int(input())

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

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

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

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

seven = 7
d = 1
while seven != 0:
    seven += pow(7*pow(10,d,k),1,k)
    seven = pow(seven,1,k)
    d += 1

print(d)

Submission status: Accepted

Solution code:
import itertools

k = int(input())

mod = set()
seven = 7 % k

for i in itertools.count():
  if seven == 0:
    print(i+1)
    break;
  elif seven in mod:
    print(-1)
    break;
  mod.add(seven)
  seven = (seven*10+7) % k

Submission status: Accepted

Solution code:
limit = pow(10, 7)
K = int(input())
num = "7"
if K % 2 == 0 or K % 5 == 0:
    print (-1)
else:
    total = 0
    flag = False
    for i in range(1, limit + 1):
        total = (total * 10 + 7) % K
        if total == 0:
            flag = True
            break
    if flag:
        print (i)
    else:
        print(-1)

Submission status: Accepted

Solution code:
K = int(input())
a = 7

for k in range(1,K+1):
  if a%K==0:
    print(k)
    exit()
  a = (10*a+7)%K

print(-1)

Submission status: Accepted

Solution code:
res = 7
cnt = 1
k = int(input().rstrip())
res_list = [0 for _ in range(k)]
flg = 0
while True:
  res %= k
  if res == 0:
    flg = 1
    break
  if res_list[res] == 1:
    break
  res_list[res] = 1
  cnt += 1
  res = res * 10 + 7
if flg == 1:
  print(cnt)
else:
  print(-1)

Submission status: Accepted

Solution code:
K = int(input())

if K%2 ==0 or K%5 == 0:
    ans = -1
else:
    det = 0
    num = 0
    cur = 0
    while True:
        num += 1
        cur += 7*pow(10,num-1,K)
        cur %= K
        #if num % 10000 == 0:
        #    print(num,cur)
        if cur == 0:
            ans = num
            break

print(ans)

Submission status: Accepted

Solution code:
k = int(input())
a = [None]*1000001
a[1]=7%k
n=0

if a[1]==0:
    print("1")
    n=1

for i in range(2,k+1):
    a[i]=(a[i-1]*10+7)%k
    if a[i]==0 and n==0:
        print("{}".format(i))
        n=1
if n==0:
    print("-1")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
dic = dict()
cnt = 1
num1 = 7 % k
num2 = 70 % k
while True:
    if dic.get(num1):break
    if (num1) == 0:
        print(cnt)
        exit()
    
    dic[num1] = 1
    num1 = (num1 + num2) %k
    num2 = (num2 * 10) %k
    cnt += 1
    #print(num1, num2)
print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
    K = int(input())
    if K % 2 == 0:
        print(-1)
        exit(0)
    if K % 5 == 0:
        print(-1)
        exit(0)
    i = 1
    term = 7
    # L = 9 * K
    # if K % 7 == 0:
    #     L = 9 * (K // 7)
    while True:
        amari = term % K
        if amari == 0:
            print(i)
            exit(0)
        term = amari * 10 + 7
        i += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
    K = int(input())
    if K % 2 == 0:
        print(-1)
        exit(0)
    if K % 5 == 0:
        print(-1)
        exit(0)
    i = 1
    term = 10
    L = 9 * K
    if K % 7 == 0:
        L = 9 * (K // 7)
    while True:
        amari = term % L
        if amari == 1:
            print(i)
            exit(0)
        term = amari * 10
        i += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
K = int(input())

N=7%K
NotFound = True

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

if (NotFound):
  print(-1)

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline
ri = lambda : int(input())
ril = lambda : list(map(int, input().split()))

def main():
  K = ri()
  m = 0
  ans = -1
  for i in range(K):
    m = (10 * m + 7) % K
    if m == 0:
      ans = i + 1
      break
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
k = int(input())
cnt = 1
num = 7

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

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

Submission status: Accepted

Solution code:
K = int(input())
base = 0

for count in range(1, K+1):
  num = base*10 + 7
  if (num%K == 0):
    print(count)
    exit()
  else:
    base = num%K
print(-1)

Submission status: Accepted

Solution code:
k = int(input())
ans = -1
seq = [0]

seq.append(7%k)
for i in range(2,k+1):
  seq.append((seq[i-1]*10+7)%k)

for j in range(1,k+1):
  if seq[j] == 0:
    ans = j
    break

print(ans)

Submission status: Accepted

Solution code:
K=int(input())
num=7

#10と互いに素ではない数は必ずあまりが出る
if K%2==0 or K%5==0:
  print(-1)
  exit()

i=1
while 1:
  num=num%K
  if num==0:
    print(i)
    break
  num = 10*num + 7
  i+=1

Submission status: Accepted

Solution code:
N = int(input())

mod_first = 7 % N
mod_next = mod_first * 11 % N

if mod_first == 0:
    print("1")
    exit()
if mod_next == 0:
    print("2")
    exit()

for i in range(10000000):
    mod_next = (mod_next * 10 + mod_first) % N
    if mod_next == 0:
        print(i + 3)
        exit()

print("-1")

Submission status: Accepted

Solution code:
def abc174_c():
    k = int(input())
    ans = -1
    if k % 2 == 0 or k % 5 == 0:
        return ans
    f = 0
    for i in range(k+1):
        f = (f * 10 + 7) % k
        if f == 0:
            ans = i + 1
            break
    return ans

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

Submission status: Accepted

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

Submission status: Accepted

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

m = set()
x = 7
ans = 1
while x > 0:
    if x < K:
        x = x*10 + 7
        ans += 1
    x = x % K
    if x in m:
        print(-1)
        exit(0)
    else:
        m.add(x)

print(ans)