# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
714090 | TheConverseEngineer | Trol (COCI19_trol) | C++17 | 1 ms | 328 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define sqr(x) ((ll)(x))*(x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int sDig(int a) {
int sum = 0;
while (a > 0) {
sum += a%10; a/=10;
}
if (sum < 10) return sum;
else return sDig(sum);
}
int Q;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> Q;
FOR(q, 0, Q) {
int l, r; cin >> l >> r;
if (r - l < 50) {
ll sum = 0;
for (int i = l; i <= r; i++) sum += (((i%9)==0)?9:(i%9));
cout << sum << "\n";
} else {
ll sum = 0;
while (l%9 != 0) {
sum += l%9; l++;
}
int fartherProduct = r / 9;
sum += 45*(fartherProduct - (l/9));
for (int i = fartherProduct*9; i <= r; i++) sum += (((i%9)==0)?9:(i%9));
cout << sum << "\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |