# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199472 | 2020-02-01T13:44:07 Z | SamAnd | Trol (COCI19_trol) | C++17 | 5 ms | 376 KB |
#include <bits/stdc++.h> using namespace std; const int N = 102; int dp[N]; int sum(int x) { int ans = 0; while (x) { ans += (x % 10); x /= 10; } return ans; } long long p(long long x) { if (x == 0) return 0; long long ans = 0; ans += (x / 9) * (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9); for (int i = 1; i <= (x % 9); ++i) ans += i; return ans; } int main() { /*for (int i = 1; i < N; ++i) { if (i <= 9) dp[i] = i; else dp[i] = dp[sum(i)]; printf("%d %d\n", i, dp[i]); }*/ int tt; scanf("%d", &tt); while (tt--) { long long l, r; scanf("%lld%lld", &l, &r); printf("%lld\n", p(r) - p(l - 1)); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 256 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |