题意:
解法:
发现n只有1e5,那么O(n)枚举a,计算a和n-a的数位和更新答案即可.
code:
#include<bits/stdc++.h>
#define int long long
#define PI pair<int,int>
using namespace std;
const int maxm=2e6+5;
int n;
int cal(int x){
int ans=0;
while(x){
ans+=x%10;
x/=10;
}
return ans;
}
void solve(){
cin>>n;
int ans=1e9;
for(int i=1;i<=n-1;i++){
ans=min(ans,cal(i)+cal(n-i));
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0);
solve();
return 0;
}