CodeForces - 1517A Sum of 2050
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 1517A Sum of 2050相关的知识,希望对你有一定的参考价值。
A. Sum of 2050
time limit per test1 second
memory limit per test256 megabytes
A number is called 2050-number if it is 2050, 20500, …, (2050⋅10k for integer k≥0).
Given a number n, you are asked to represent n as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that.
Input
The first line contains a single integer T (1≤T≤1000) denoting the number of test cases.
The only line of each test case contains a single integer n (1≤n≤1018) denoting the number to be represented.
Output
For each test case, output the minimum number of 2050-numbers in one line.
If n cannot be represented as the sum of 2050-numbers, output −1 instead.
Example
input
6
205
2050
4100
20500
22550
25308639900
output
-1
1
2
1
2
36
Note
In the third case, 4100=2050+2050.
In the fifth case, 22550=20500+2050.
问题链接:CodeForces - 1517A Sum of 2050
问题简述:(略)
问题分析:(略)
AC的C++语言程序如下:
/* CodeForces - 1517A Sum of 2050 */
#include <bits/stdc++.h>
using namespace std;
const int M = 2050;
int main()
{
int t;
scanf("%d", &t);
while (t--) {
long long n, ans = -1;
scanf("%lld", &n);
if (n % M == 0) {
ans = 0;
n /= M;
while (n) {
ans += n % 10;
n /= 10;
}
}
printf("%lld\\n", ans);
}
return 0;
}```
以上是关于CodeForces - 1517A Sum of 2050的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces 85D Sum of Medians(线段树)
codeforces 85D. Sum of Medians
codeforces 616E. Sum of Remainders 数学
CodeForces - 1327A Sum of Odd Integers(数学+思维)