# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
217359 | bayemirov | Trol (COCI19_trol) | C++17 | 5 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//bayemirov
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define pb push_back
ll ans;
ll g(ll x) {
return x * (x + 1) / 2;
}
ll sumofDigits(ll x, ll res = 0) {
while (x) {
res += x % 10;
x /= 10;
}
return res;
}
ll get(ll x) {
while (x >= 10)
x = sumofDigits(x);
return x;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int q;
cin >> q;
while (q--) {
ll l, r;
cin >> l >> r;
if ((r-l+1)/9 == 0) {
while (l <= r) {
ans += sumofDigits(l);
l++;
}
cout << ans, exit(0);
}
ans = (r-l+1)/9 * 45;
ll pref = get(l);
ll suff = get(r);
while (pref > 1ll && pref < 10ll)
ans += pref++;
if (suff < 9)
ans += g(suff);
cout << ans << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |