제출 #714090

#제출 시각아이디문제언어결과실행 시간메모리
714090TheConverseEngineerTrol (COCI19_trol)C++17
30 / 50
1 ms328 KiB
#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 timeMemoryGrader output
Fetching results...