단순 귀속
5049 단어 귀속
/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
typedef long long LL;
LL three[40];
LL work(int k, int a, int b) {
int side = 1 << (k - 1);
if (a > side || b < 1) {
return 0;
}
if (a <= 1 && b >= side) {
return three[k - 1];
}
int aa = a - (1 << (k - 2));
int bb = b - (1 << (k - 2));
return 2 * work(k - 1, a, b) + work(k - 1, aa, bb);
}
int main() {
int T, a, b, k;
three[0] = 1;
for (int i = 1; i <= 30; i++) {
three[i] = three[i - 1] * 3;
}
scanf("%d", &T);
for (int t = 1; t <= T; t++) {
scanf("%d%d%d", &k, &a, &b);
printf("Case %d: %lld
", t, work(k, a, b));
}
return 0;
}