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

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int dp[200][100000];
signed main(){
	ll k;cin>>k;
	memset(dp,0x3f,sizeof(dp));
	//int sum=0;
	//string s=to_stirng(k);
	/*for(char c:s){
		sum+=c-'0';
	}*/
	//dp[to_string(k).size()][0]=sum;
	dp[0][0]=0;
	rep(i,190)rep(j,k){
		if(dp[i][j]==INF)continue;
		rep(t,9){
			if(i==0&&t==0)continue;
			dp[i+1][(j*10+t)%k]=min(dp[i+1][(j*10+t)%k],dp[i][j]+t);
		}
	}
	int Min=INF;
	rep(i,200){
		if(i)Min=min(Min,dp[i][0]);
	}
	cout<<Min<<endl;
}