Language: C++

#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MX=1*1e5+2;
const long long INF = 1e18;
ll N, M, k;
ll dig(ll a)
{
    ll s=0;
    if(a < 0) return 1e9;
    while(a > 0)
    {
        s+=a%10;
        a/=10;
    }
    return s;
}
int dp[200][MX][2];
int f(int i, ll sum, bool take)
{
    if(i == 199)
    {
        ///  cout<<"s "<<sum<<"\n";
        if(take &&sum % k == 0) return 0;
        return 1e11;
    }
    int &ret=dp[i][sum][take];
    if(ret != -1) return ret;
    ret=1e12;
    ll dig;
    if(take) dig=0;
    else dig=1;
    for(; dig<=9; dig++)
    {
        ret=min(ret, dig+f(i+1, (sum*10+dig)%k, dig?1:take));
    }
    return ret;
}
int main()
{
    cin>>k;
    ll ans=1e18;
    memset(dp, -1, sizeof dp);
    ans=min(ans, f(0, 0, 0));
    cout<<ans;
    return 0;
 
}

Compiler output:
a.cc: In function 'int f(int, long long int, bool)':
a.cc:29:16: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+11' to '2147483647' [-Woverflow]
   29 |         return 1e11;
      |                ^~~~
a.cc:33:9: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+12' to '2147483647' [-Woverflow]
   33 |     ret=1e12;
      |         ^~~~
a.cc:39:16: error: no matching function for call to 'min(int&, long long int)'
   39 |         ret=min(ret, dig+f(i+1, (sum*10+dig)%k, dig?1:take));
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:39:16: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   39 |         ret=min(ret, dig+f(i+1, (sum*10+dig)%k, dig?1:take));
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:39:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   39 |         ret=min(ret, dig+f(i+1, (sum*10+dig)%k, dig?1:take));
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:48:12: error: no matching function for call to 'min(long long int&, int)'
   48 |     ans=min(ans, f(0, 0, 0));
      |         ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:48:12: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   48 |     ans=min(ans, f(0, 0, 0));
      |         ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:48:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   48 |     ans=min(ans, f(0, 0, 0));
      |         ~~~^~~~~~~~~~~~~~~~~