Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2)

该博客讨论了Codeforces竞赛中的问题A,即判断一个数是否能表示为2050, 20500, 205000等的和,输出使用最少数字的个数。解决方案涉及到数的整除性和位数求和。" 131318746,18873188,Python按行拼接技巧:提高代码可读性与协作效率,"['Python', '编程技巧', '代码组织', '可读性']
摘要由CSDN通过智能技术生成

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值