Problem:


Score : 700 points

Problem Statement

Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.

Constraints

2 \leq K \leq 10^5

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K.

Sample Input 1

6

Sample Output 1

3

12=6×2 yields the smallest sum.

Sample Input 2

41

Sample Output 2

5

11111=41×271 yields the smallest sum.

Sample Input 3

79992

Sample Output 3

36



Sample input:
6


Sample output:
3

Submission status: Wrong Answer

Solution code:
from collections import deque


def solve(K):
    s = 1
    q = deque()
    q.append(s)
    dists = {}
    dists[s] = 1
    while len(q) > 0:
        n = q.pop()
        if n == 0:
            break
        m = (n*10)%K
        if m not in dists:
            dists[m] = dists[n]
            q.append(m)
        if dists[m] > dists[n]:
            dists[m] = dists[n]
        if n % 10 != 9:
            m = (n+1)%K
            if m not in dists:
                dists[m] = dists[n] + 1
                q.appendleft(m)
            if dists[m] > dists[n] + 1:
                dists[m] = dists[n] + 1
    return dists[0]


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque


def solve(K):
    s = 1
    q = deque()
    q.append(s)
    dists = {}
    dists[s] = 1
    while len(q) > 0:
        n = q.pop()
        if n == 0:
            break
        m = (n*10)%K
        if m not in dists:
            dists[m] = dists[n]
            q.append(m)
        if n % 10 != 9:
            m = (n+1)%K
            if m not in dists:
                dists[m] = dists[n] + 1
                q.appendleft(m)
    return dists[0]


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque


def solve(K):
    s = 1
    q = deque()
    q.append(s)
    dists = {}
    dists[s] = 1
    while len(q) > 0:
        n = q.pop()
        if n == 0:
            break
        if n % 10 != 9:
            m = (n+1)%K
            if m not in dists:
                dists[m] = dists[n] + 1
                q.appendleft(m)
        m = (n*10)%K
        if m not in dists:
            dists[m] = dists[n]
            q.append(m)
    return dists[0]


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def to10(n):
	a=[]
	while(n>0):
		a.append(n%10)
		n//=10
	return a		




K=int(input())






#1>2
#2>4
#3>6
#8>16 7


#それぞれの1桁での表ができる
#10倍で変わらない??

a=to10(K)


X=[[(i*j)//10+(i*j)%10 for i in range(10)] for j in range(10)]


print(min([sum([X[i][a[j]] for j in range(len(a))]) for i in range(1,10)]))




# nをabc倍するのは. n(100a+10b+c)
# na+nb+ncで計算可能
# 

#8*12=96: 15   8+7=15
#99*9=891: 18  9+9=18

Submission status: Wrong Answer

Solution code:
import datetime
t=datetime.datetime.now()
#print(t)
k=int(input())
ans=9*10**5
n=10**3
#for i in range(1,n):
dt=datetime.datetime.now()-t
i=0
while(dt.microseconds<0.99*10**6):
    i+=1
    s=str(i*k)
    cnt=0
    for j in s:
        cnt+=int(j)
        #print(j,cnt)
    ans=min(ans,cnt)
    dt=datetime.datetime.now()-t
print(ans)

Submission status: Wrong Answer

Solution code:
k=int(input())
ans=9*10**5
n=10**3
for i in range(1,n):
    s=str(i*k)
    cnt=0
    for j in s:
        cnt+=int(j)
        #print(j,cnt)
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
k=int(input())
c=float("inf")
for i in range(1,10**5):
    c=min(c,sum([int(d) for d in str(k*i)]))
print(c)

Submission status: Wrong Answer

Solution code:
k = int(input())

def sum_keta(num):
  ans = 0
  for i in str(num):
    ans = ans + int(i)
  return ans

min_sum_keta = float("inf")
limit = k*10**len(str(k)+"1")
add = k
while k < limit:
  min_sum_keta = min(min_sum_keta,sum_keta(k))
  k += add
print(min_sum_keta)

Submission status: Wrong Answer

Solution code:
k = int(input())

def sum_keta(num):
  ans = 0
  for i in str(num):
    ans = ans + int(i)
  return ans

min_sum_keta = float("inf")
limit = k*10**len(str(k))
add = k
while k < limit:
  min_sum_keta = min(min_sum_keta,sum_keta(k))
  k += add
print(min_sum_keta)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    ans = 10**9
    for i in range(1, 10**5):
        m = sum([int(c) for c in str(N * i)])
        ans = min(ans, m)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    if s+t == t[::-1]+s[::-1]:
        print("YES")
    else:
        print("NO")

#B
def B():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if i*i <= n:
            print(i*i)
            quit()
#C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a,b[i])
        q[i] = j
    for i in range(n-1):
        q[i+1] += q[i]
    q.insert(0,0)
    for i in range(n):
        j = bisect.bisect_left(b,c[i])
        ans += q[j]
    print(ans)
#D
def D():
    def f(n):
        l = n
        ans = 0
        while l > 0:
            ans += l%10
            l //= 10
        return ans
    k = I()
    l = [9,99,999,9999,99999]
    for i in l[::-1]:
        if k%i == 0:
            print(int(math.log(i+1,10))*9)
            quit()
    l = [3,33,333,3333,33333]
    for i in l[::-1]:
        if k%i == 0:
            print(int(math.log(i,10)+1)*3)
            quit()

    ans = 1
    i = 2
    a = k
    if k == 1:
        print(1)
        quit()
    while i <= k:
        if k%i == 0:
            while k%i == 0:
                k //= i
            d = float("inf")
            for j in range(1,1000000):
                c = f(i*j)
                if c < d:
                    d = c
            ans = max(ans,d)
        i += 1
    print(ans)

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    if s+t == t[::-1]+s[::-1]:
        print("YES")
    else:
        print("NO")

#B
def B():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if i*i <= n:
            print(i*i)
            quit()
#C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a,b[i])
        q[i] = j
    for i in range(n-1):
        q[i+1] += q[i]
    q.insert(0,0)
    for i in range(n):
        j = bisect.bisect_left(b,c[i])
        ans += q[j]
    print(ans)
#D
def D():
    def f(n):
        l = n
        ans = 0
        while l > 0:
            ans += l%10
            l //= 10
        return ans
    k = I()
    l = [9,99,999,9999,99999]
    for i in l[::-1]:
        if k%i == 0:
            print(int(math.log(i+1,10))*9)
            quit()
    l = [3,33,333,3333,33333]
    for i in l[::-1]:
        if k%i == 0:
            print(int(math.log(i,10)+1)*3)
            quit()

    ans = float("inf")
    i = 2
    a = k
    if k == 1:
        print(1)
        quit()
    while i <= k:
        if k%i == 0:
            while k%i == 0:
                k //= i
            for j in range(1,100000):
                c = f(i*j)
                if c < ans:
                    ans = c
        i += 1
    print(ans)

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    if s+t == t[::-1]+s[::-1]:
        print("YES")
    else:
        print("NO")

#B
def B():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if i*i <= n:
            print(i*i)
            quit()
#C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a,b[i])
        q[i] = j
    for i in range(n-1):
        q[i+1] += q[i]
    q.insert(0,0)
    for i in range(n):
        j = bisect.bisect_left(b,c[i])
        ans += q[j]
    print(ans)
#D
def D():
    l = 2**15
    bi = [list(map(int,bin(i)[2::])) for i in range(1,l)]
    k = I()
    while k %2 == 0:
        k //= 2
    while k%5 == 0:
        k //= 5
    if (k+1)%10 == 0:
        ans = int(math.log(k+1,10))*9
        print(ans)
        quit()
    c = 2
    a = k
    ans = float("inf")

    while c**2 <= a:
        if k%c == 0:
            while k%c == 0:
                k //= c
        for l in bi:
            i = 0
            d = 1
            b = 0
            for j in range(len(l))[::-1]:
                b += l[j]
                i += d*l[j]
                d *= 10
            if i%c == 0:
                ans = min(ans,b)
        c += 1
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
a = input()
b = input()
if a[2] == b[0] and a[1] == b[1] and a[0] == b[2]:
    print("YES")
else:
    print("NO")
"""

#B
"""
n = I()
n = int(math.sqrt(n))
print(n**2)
"""

#C
"""
n = I()
a = LI()
a.sort()
b = LI()
b.sort()
c = LI()
c.sort()
ans = 0
for i in b:
    x = bisect.bisect_left(a, i)
    x = x * (n - bisect.bisect_right(c, i))
    ans += x
print(ans)
"""

#D
k = I()
ans = list(str(k))
ans = sum(list(map(int, ans)))
for i in range(2, 10**6):
    bk = list(str(k*i))
    bk = list(map(int, bk))
    ans = min(ans, sum(bk))
print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    if s+t == t[::-1]+s[::-1]:
        print("YES")
    else:
        print("NO")

#B
def B():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if i*i <= n:
            print(i*i)
            quit()
#C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a,b[i])
        q[i] = j
    for i in range(n-1):
        q[i+1] += q[i]
    q.insert(0,0)
    for i in range(n):
        j = bisect.bisect_left(b,c[i])
        ans += q[j]
    print(ans)
#D
def D():
    l = 2**15
    bi = [list(map(int,bin(i)[2::])) for i in range(1,l)]
    k = I()
    while k %2 == 0:
        k //= 2
    while k%5 == 0:
        k //= 5
    if (k+1)%10 == 0:
        ans = int(math.log(k+1,10))*9
        print(ans)
        quit()
    ans = float("inf")
    for l in bi:
        i = 0
        d = 1
        b = 0
        for j in range(len(l))[::-1]:
            b += l[j]
            i += d*l[j]
            d *= 10
        if i%k == 0:
            ans = min(ans,b)
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
a = input()
b = input()
if a[2] == b[0] and a[1] == b[1] and a[0] == b[2]:
    print("YES")
else:
    print("NO")
"""

#B
"""
n = I()
n = int(math.sqrt(n))
print(n**2)
"""

#C
"""
n = I()
a = LI()
a.sort()
b = LI()
b.sort()
c = LI()
c.sort()
ans = 0
for i in b:
    x = bisect.bisect_left(a, i)
    x = x * (n - bisect.bisect_right(c, i))
    ans += x
print(ans)
"""

#D
k = I()
ans = list(str(k))
ans = sum(list(map(int, ans)))
for i in range(2, 10):
    bk = list(str(k*i))
    bk = list(map(int, bk))
    ans = min(ans, sum(bk))
print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    if s+t == t[::-1]+s[::-1]:
        print("YES")
    else:
        print("NO")

#B
def B():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if i*i <= n:
            print(i*i)
            quit()
#C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a,b[i])
        q[i] = j
    for i in range(n-1):
        q[i+1] += q[i]
    q.insert(0,0)
    for i in range(n):
        j = bisect.bisect_left(b,c[i])
        ans += q[j]
    print(ans)
#D
def D():
    def f(n):
        l = n
        ans = 0
        while l > 0:
            ans += l%10
            l //= 10
        return ans
    k = I()
    ans = float("inf")
    for i in range(1,1000000):
        a = f(k*i)
        if a < ans:
            ans = a
    print(ans)

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    if s+t == t[::-1]+s[::-1]:
        print("YES")
    else:
        print("NO")

#B
def B():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if i*i <= n:
            print(i*i)
            quit()
#C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a,b[i])
        q[i] = j
    for i in range(n-1):
        q[i+1] += q[i]
    q.insert(0,0)
    for i in range(n):
        j = bisect.bisect_left(b,c[i])
        ans += q[j]
    print(ans)
#D
def D():
    def f(n):
        l = n
        ans = 0
        while l > 0:
            ans += l%10
            l //= 10
        return ans
    k = I()
    ans = float("inf")
    for i in range(1,100000):
        a = f(k*i)
        if a < ans:
            ans = a
    print(ans)

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Wrong Answer

Solution code:
def f(x):
    ret = 0
    while x:
        ret += x % 10
        x //= 10
    return ret
k = int(input())
m = 10 ** 9
l = k
while l % 2 == 0:
    l //= 2
while l % 5 == 0:
    l //= 5
if l == 1:
    print(1)
    exit()
for i in range(1, 1000000):
    m = min(m, f(k*i))
print(m)

Submission status: Wrong Answer

Solution code:
def f(x):
    ret = 0
    while x:
        ret += x % 10
        x //= 10
    return ret
k = int(input())
m = 10 ** 9
l = k
while l % 2 == 0:
    l //= 2
while l % 5 == 0:
    l //= 5
if l == 1:
    print(1)
    exit()
for i in range(1, 100000):
    m = min(m, f(k*i))
print(m)

Submission status: Wrong Answer

Solution code:
k = int(input())
def digitsum(n):
  return sum(map(int, list(str(n))))
ans = digitsum(k)
for i in range(2, 100000):
  ans = min(ans, digitsum(k*i))
print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())
loop = 10**3
klist = list(str(K))
klen = len(klist)
MIN = 0
for i in range(klen):
    MIN+=int(klist[i])
j = 0
for j in range(loop):
    K = K*(j+2)
    SUM = 0
    klist = list(str(K))
    klen = len(klist)
    k = 0
    for k in range(klen):
        SUM+=int(klist[k])
    if MIN >= SUM:
        MIN = SUM
    if MIN == 1:
        break
print(MIN)

Submission status: Wrong Answer

Solution code:
K = int(input())
def Dmonu(K):
    loop = 10**10
    klist = list(str(K))
    klen = len(klist)
    MIN = 0
    for i in range(klen):
        MIN+=int(klist[i])
    j = 0
    for j in range(loop):
        K = K*(j+2)
        SUM = 0
        klist = list(str(K))
        klen = len(klist)
        k = 0
        for k in range(klen):
            SUM+=int(klist[k])
        if MIN >= SUM:
            MIN = SUM
        if MIN <= klen:
            break
    return MIN

if K%2==0 or K%5==0:
    print(1)
else:
    print(Dmonu(K))

Submission status: Wrong Answer

Solution code:
K = int(input())
loop = 10**10
klist = list(str(K))
klen = len(klist)
MIN = 0
for i in range(klen):
    MIN+=int(klist[i])
i = 0
for i in range(loop):
    K = K*(i+2)
    SUM = 0
    klist = list(str(K))
    klen = len(klist)
    j = 0
    for j in range(klen):
        SUM+=int(klist[j])
    if MIN >= SUM:
        MIN = SUM
    if MIN <= klen:
        break
print(MIN)

Submission status: Wrong Answer

Solution code:
K = int(input())
loop = 10**10
klist = list(str(K))
klen = len(klist)
MIN = 0
for i in range(klen):
    MIN+=int(klist[i])
for i in range(loop):
    K = K*(i+2)
    SUM = 0
    klist = list(str(K))
    klen = len(klist)
    for j in range(klen):
        SUM+=int(klist[j])
    if MIN >= SUM:
        MIN = SUM
    if MIN <= klen:
        break
print(MIN)

Submission status: Wrong Answer

Solution code:
K = int(input())
loop = 10**10
klist = list(str(K))
klen = len(klist)
MIN = 0
for i in range(klen):
    MIN+=int(klist[i])
for i in range(loop):
    K = K*(i+2)
    SUM = 0
    klist = list(str(K))
    klen = len(klist)
    for j in range(klen):
        SUM+=int(klist[j])
    if MIN >= SUM:
        MIN = SUM
    if MIN < klen:
        break
print(MIN)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019

def sum_of_number( n ):
    s=0
    for i in range ( len(n)):
        s+= int(n[i])
    return s

K= (raw_input())

smallest= int( sum_of_number ( K ) )

count = 2
while count < 10:
    num = int( sum_of_number( str( int(K) * count) ) )
    if smallest > num:
        smallest = num
    
    count +=1


print smallest

Submission status: Wrong Answer

Solution code:
K = int(input())


def sum_all(n):
    res = 0
    while n//10 != 0:
        res += n % 10
        n //= 10
    res += n
    return res

ans = 10**10
for i in range(1, 10):
    ans = min(ans, sum_all(K*i))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input())
G = [[] for i in range(K)]
for i in range(K):
    G[i].append(((10 * i) % K, 0))
    G[i].append(((i + 1) % K, 1))

dist = [float('inf')] * K
dist[1] = 1
que = deque()
que.append(1)

while que:
    n = que.pop()
    for v, c in G[n]:
        if dist[v] != float('inf'):
            continue
        dist[v] = dist[n] + c
        if c == 0:
            que.append(v)
        else:
            que.appendleft(v)

print(dist[0])

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input())
G = [[] for i in range(K)]
for i in range(K):
    G[i].append(((i + 1) % K, 1))
    G[i].append(((10 * i) % K, 0))

dist = [float('inf')] * K
dist[1] = 1
que = deque()
que.append(1)

while que:
    n = que.pop()
    for v, c in G[n]:
        if dist[v] != float('inf'):
            continue
        dist[v] = dist[n] + c
        if c == 0:
            que.append(v)
        else:
            que.appendleft(v)

print(dist[0])

Submission status: Wrong Answer

Solution code:
import math
K = int(input())


def digitsum(x):
    if x > 9:
        y = 10**(int(math.log10(x)))
        return x // y + digitsum(x % y)
    else:
        return x


ans = 10**5
for i in range(1, 10**(int(math.log10(K)) + 1)):
    ans = min([ans, digitsum(K * i)])
print(ans)

Submission status: Wrong Answer

Solution code:

N=int(input())
min_ans=10**28
for i in range(1,100000):
    a = N*i
    a = str(a)
    ans=0
    for i in range(len(a)):
        ans+=int(a[i])
    min_ans=min(ans,min_ans)
print(min_ans)

Submission status: Wrong Answer

Solution code:

N=int(input())
min_ans=10**28
for i in range(1,10):
    a = N*i
    a = str(a)
    ans=0
    for i in range(len(a)):
        ans+=int(a[i])
    min_ans=min(ans,min_ans)
print(min_ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int( input())
V = [0]*K
d = deque([(1,1)])
while 1:
    w, v = d.popleft()
    if V[v] == 1:
        continue
    V[v] = 1
    if V[ (v+1)%K] == 0:
        if (v+1)%K == 0:
            ans = w+1
            break
        d.append((w+1 ,(v+1)%K))
    if V[ (v*10)%K] == 0:
        d.appendleft((w, (v*10)%K))
        if (v*10)%K == 0:
            ans = w
            break
print(ans)

Submission status: Wrong Answer

Solution code:
k = int(input())
sum = 0
sumli = []
for i in range(1, 10**5+1):
    t = k * i
    u = list(str(t))
    for j in u:
        sum += int(j)
    sumli.append(sum)
    sum = 0
print(min(sumli))

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input())
G = [[] for i in range(K)]

for n in range(K):
    G[n].append([(n + 1) % K, 1])
    G[n].append([(10 * n) % K, 0])

que = deque([[1, 1]])
dist = [float('inf')] * K
dist[1] = 1

while que:
    node, cost = que.pop()
    for e, e_cost in G[node]:
        if dist[e] != float('inf'):
            continue

        if e_cost == 0:
            dist[e] = cost + 0
            que.append([e, cost + 0])

        if e_cost == 1:
            dist[e] = cost + 1
            que.appendleft([e, cost + 1])

print(dist[0])

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input())
G = [[] for i in range(K)]

for n in range(K):
    G[n].append([(n + 1) % K, 1])
    G[n].append([(10 * n) % K, 0])

que = deque([[1, 1]])
dist = [float('inf')] * K

while que:
    node, cost = que.pop()
    dist[node] = cost
    
    for e, e_cost in G[node]:
        if dist[e] != float('inf'):
            continue

        if e_cost == 0:
            que.append([e, cost + 0])

        if e_cost == 1:
            que.appendleft([e, cost + 1])

print(dist[0])

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input())
G = [[] for i in range(K)]

for n in range(K):
    G[n].append([(n + 1) % K, 1])
    G[n].append([(10 * n) % K, 0])

que = deque([[1, 1]])
dist = [float('inf')] * K

while que:
    node, cost = que.pop()
    dist[node] = cost

    for e, e_cost in G[node]:
        if dist[e] != float('inf'):
            continue

        if e_cost == 0:
            que.append([e, cost + 0])

        if e_cost == 1:
            que.appendleft([e, cost + 1])

        if e == 0:
            print(cost + e_cost)
            exit()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 20 12:35:35 2018

@author: maezawa
"""

k = int(input())
ans= 10**10
for i in range(2,10**6):
    o = list(str(i*k))
    sumorder = sum(map(int,o))
    if sumorder < ans:
        ans = sumorder
print(ans)

Submission status: Wrong Answer

Solution code:
k = int(input())
ans= 10**10
for i in range(2,10**5):
    o = list(str(i*k))
    sumorder = sum(map(int,o))
    if sumorder < ans:
        ans = sumorder
print(ans)

Submission status: Wrong Answer

Solution code:
K = int(input())

min_s = 9999
for i in range(10**6):
    n = K*(i+1)
    s = sum(map(int,str(n)))
    if s < min_s:
        min_s = s
print(min_s)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def digit_sum(num:int, base:int) -> int:
    if num < base:
        return num
    else:
        return digit_sum(int(num/base), base) + (num % base)

from collections import deque

k = ni()
que = deque([1])

kmod = [0]*k

while kmod[0] == 0:
    cur = que.popleft()
    if kmod[cur%k] == 0:
        kmod[cur%k] = digit_sum(cur,10)
        
        if kmod[cur%k] == 0:
            que.appendleft(10*cur)
        if kmod[(cur+1)%k] == 0:
            que.append(cur+1)
            
        
print(kmod[0])

Submission status: Wrong Answer

Solution code:
from math import log10
k = int(input())
ans = float("inf")
for i in range(1, 8*10**5):
    ans = min(ans, sum(map(int, str(k*i))))
print(ans)

Submission status: Wrong Answer

Solution code:
from math import log10
k = int(input())
ans = float("inf")
for i in range(1, 2*10**5):
    ans = min(ans, sum(map(int, str(k*i))))
print(ans)

Submission status: Wrong Answer

Solution code:
k=int(input())

ans=10000
for i in range(1,k):
    s=str(k*i)
    temp=0
    for c in s:
        temp+=int(c)
    ans=min(ans,temp)
print(ans)

Submission status: Wrong Answer

Solution code:
k=int(input())

ans=10000
for i in range(1,10):
    s=str(k*i)
    temp=0
    for c in s:
        temp+=int(c)
    ans=min(ans,temp)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from heapq import heappop, heappush
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]


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


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


def main():
    K = int(input())
    dp = [INF] * K
    dp[1] = 1

    heap = []
    heappush(heap, 1)

    while len(heap) != 0:
        p = heappop(heap)
        if dp[(p + 1) % K] > dp[p] + 1:
            dp[(p + 1) % K] = dp[p] + 1
            heappush(heap, (p + 1) % K)
        if dp[(p * 10) % K] > dp[p]:
            dp[(p * 10) % K] = dp[p]
            heappush(heap, (p * 10) % K)

        if dp[0] != INF:
            break

    print(dp[0])


if __name__ == '__main__':
    main()