-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolve3.cpp
More file actions
35 lines (34 loc) · 738 Bytes
/
Copy pathsolve3.cpp
File metadata and controls
35 lines (34 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int main(){
IOS
int t;
cin >> t;
while(t--){
int l, r;
cin >> l >> r;
int tmp = 1, cnt = 0;
while(tmp < l){
tmp *= 3;
cnt++;
}
tmp = l;
int idx = 1, ans = 1;
while(tmp <= r){
if((tmp * 3) - 1 > r){
ans += (r - tmp) * cnt;
}
else{
ans += ((tmp * 3) - tmp) * cnt;
}
tmp *= 3;
cnt += idx;
idx++;
}
cout << ans + 1 << '\n';
}
return 0;
}