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 <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <vector>
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n - 1); i >= 0; --i)
#define mod 100000
#define INF 93193111451418101
#define MIN -933111451418101
using namespace std;
typedef pair<ll, ll> P;

template <typename T, typename U>
typename std::enable_if<std::rank<T>::value == 0>::type fill_all(T &arr,
                                                                 const U &v) {
  arr = v;
}
template <typename ARR, typename U>
typename std::enable_if<std::rank<ARR>::value != 0>::type fill_all(ARR &arr,
                                                                   const U &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------?????°-----------------------//
ll n, yo[114515];
std::vector<ll> a, b, c;
//-------------------??¢??°----------------------//
ll ketawa(ll num) {
  ll cnt = 0;
  while (num) {
    cnt += num % 10;
    num /= 10;
  }
  return cnt;
}
int main() {
  cin >> n;
  /*  REP(i, n) {
      while (n % (i + 2) == 0) {
        if (n / (i + 2) == 1) {
          break;
        }
        n /= (i + 2);
      }
    }*/
  ll hoge = INF;
  REP(i, 500000) { hoge = min(hoge, ketawa((i + 1) * n)); }
  cout << hoge << endl;
}