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

Solution code:
# coding: utf-8
# Your code here!

from datetime import datetime
K = int(input())
start = datetime.now()
def KSum(n):
    k = 0
    for i in str(n):
        k += int(i)
    return k

m = KSum(K)
j = 1
while((datetime.now()-start).total_seconds() < 1.8):
    for x in range(100):
	    P = KSum(K*j)
    	if m > P:
        	m = P
    	j += 1
print(m)

Submission status: Runtime Error

Solution code:
from datetime import datetime
K = int(input())
start = datetime.now()
def KSum(n):
    k = 0
    for i in str(n):
        k += int(i)
    return k

m = KSum(K)
j = 1
while((datetime.now()-start).total_seconds() < 1.8):
  	for x in range(100):
	    P = KSum(K*j)
    	if m > P:
        	m = P
    	j += 1
print(m)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <list>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <cstring>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;

const int INF=0x3f3f3f3f;
const int SIZE=100005;

deque<int> que;
int dist[SIZE];

int main(){
	int k;
	cin>>k;
	for(int i=0;i<k;i++) dist[i]=INF;
	dist[1]=1;
	que.push_back(1);
	while(!que.empty()){
		int u=que.front();
		que.pop_front();
		if(dist[(u*10)%k]>dist[u]){
			dist[(u*10)%k]=dist[u];
			que.push_front((u*10)%k);
		}
		if(dist[(u+1)%k]>dist[u]){
			dist[(u+1)%k]=dist[u]+1;
			que.push_back((u+1)%k);
		}
	}
	cout<<dist[0]<<endl;
}

Submission status: Runtime Error

Solution code:
k=int(input())
while k%2 == 0:
    k //=2
while k%5 == 0:
    k //=5

lst = [k+1]*k
queue = [1]
lst[1] = 1
while queue:
    a = queue.pop(0)
    if lst[a*10%k] > lst[a]:
        lst[a*10%k] = lst[a]
        queue.insert(0,a*10%k)
    if lst[(a+1)%k]>= lst[a]+1:
        lst[(a+1)%k] = lst[a]+1
        queue.append((a+1)%k)
print(lst[0])

Submission status: Runtime Error

Solution code:
a=int(input())
x1=0
x2=0
for j in range(1,17):
  if a % 2**j==0:
    x1 = j
for j in range(1,17):
  if a % 5**j==0:
    x2 = j
c = str(a * (5**(x1-x2)))

for j in range(len(c),0,-1):
  if c[j-1]=='0':
    c=c[:j]

y=10000000000000
for j in range(1,1000):
  b=sum([int(i) for i in list(str(c * j))])
  y=min(y , b)

print(y)

Submission status: Runtime Error

Solution code:
a=int(input())
x=0
for j in range(1,17):
  if a % 2**j==0:
    x1 = j
for j in range(1,17):
  if a % 5**j==0:
    x2 = j
c = str(a * (5**(x1-x2)))

for j in range(len(c),0,-1):
  if c[j-1]=='0':
    c=c[:j]

y=10000000000000
for j in range(1,1000):
  b=sum([int(i) for i in list(str(c * j))])
  y=min(y , b)

print(y)

Submission status: Runtime Error

Solution code:
k=input()
print min([sum(map(int, list(strk*i))) for i in xrange(1, 10**(len(str(k))+1))])

Submission status: Runtime Error

Solution code:
k=input()
print min([sum(map(int, list(strk*i)))) for i in xrange(1, 10**(len(str(k))+1))])

Submission status: Runtime Error

Solution code:
import math

def small_multiple(K):
    n_digits = int(math.log10(float(K))) + 1
    min_val = K
    for i in range(int(10**n_digits)):
        K_m = K*(i+1)
        K_m_n_digits = int(math.log10(float(K_m))) + 1
        val = 0
        for j in range(K_m_n_digits):
            val += (K_m % (10**(j+1))) // (10**j)
        if val < min_val:
            min_val = val
    return min_val

if __name__ == "__main__":
    # raw_input()
    # nums = [int(i) for i in raw_input().split()]
    # print(" ".join([str(num) for num in reverse_append(nums)]))
    run_test(small_multiple, test_pair)
    K = int(input())
    print(small_multiple(K))
# ===

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
array = []
X = int(100000/N)
     
for i in range(X):
    Y = str(N*(i+1))
    a_list = list(map(int,Y))
    ddd = sum(a_list)
    if ddd < array[1]:
        array.pop(0)
        array.append(ddd)
    
        
print(int(array[0]))

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
array = []
X = int(100000/N)
     
for i in range(X):
    Y = N*(i+1)
    STR = str(Y)
    a_list = list(map(float,STR))
    ddd = sum(a_list)
    array.append(sum(ddd))
        
sum_list = min(array)
print(int(sum_list))

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
array = []
X = int(100000/N)
     
for i in range(X):
    Y = N*(i+1)
    STR = str(Y)
    a_list = list(map(float,STR))
    ddd = sum(a_list)
    array.append(sum(ddd)
        
sum_list = min(array)
print(int(sum_list)

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
array = []
X = int(100000/N)
     
for i in range(X):
    Y = N*(i+1)
    STR = str(Y)
    a_list = list(map(float,STR))
    array.append(sum(a_list))
        
sum_list = min(a_list)
print(int(sum_list)

Submission status: Runtime Error

Solution code:
N = int((input()))

A = [int(i) for i in input().split()]

B = [int(i) for i in input().split()]

C = [int(i) for i in input().split()]

can_make = 0
for upp in range(N):
    for midd in range(N):
        for loww in range(N):
            if A[upp] < B[midd] < C[loww]:
                can_make += 1

print(can_make)

Submission status: Runtime Error

Solution code:
    def s(n):
        return sum(int(c) for c in str(n))
     
    def main():
        n = int(input())
        powers = [10]
        for _ in range(10000):
            powers.append(powers[-1] * 10)
     
        digsum = s(n)
        for power in powers:
            if power < n:
                continue
            k = (power + n - 1) // n
            # print(power, n * k)
            digsum = min(digsum, s(n * k))
     
        print(digsum)
     
    main()