Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)
作者:互联网
A. Sum of 2050
输入一个数,若与若干个2050,20500,205000······的和相等,则输出用到数字最少的个数,不能则输出-1.
如果可以,那么这个数必然可以被2050整除,如果不能,直接输出-1,后面的数都是2050的整十倍,最后最少的个数就是n除2050的商上的各位数之和。
来自 https://codeforces.com/contest/1517/problem/A
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<iterator>
using namespace std;
typedef long long ll;
template<class T>T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
#define setpre(a) cout<<fixed<<setprecision(a)
#define FOR(i,n) for(int i=0;i<n;i++)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define bug cout<<"!!!\n";
void solve() {
ll n;
cin >> n;
if (n < 2050||((n%2050)>0)) {
cout << "-1\n";
}
else {
ll m, ans = 0;
m = n / 2050;
while (m) {
ans += m % 10;
m /= 10;
}
cout << ans << endl;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
标签:2050,cout,718,ll,cin,ans,Div,include 来源: https://blog.csdn.net/qq_54233803/article/details/116085071