根据图形推公式
设g(k,i)为k小时后最下面i行红气球个数
#include<cstdio>
#define LL long long
#define maxn 1000
using namespace std;
LL c[maxn];
LL pow(LL x,LL n)
{
LL res = 1;
while(n > 0)
{
if(n&1)res=res*x;
x=x*x;
n>>=1;
}
return res;
}
LL g(LL k,LL i)
{
if(i<=0||i>pow(2,k))return 0;
if(k<=0)return 1;
if(i>=pow(2,k-1))
return 2*g(k-1,i-pow(2,k-1))+c[k-1];
else return g(k-1,i);
}
int main()
{
int n;
LL k,a,b;
scanf("%d",&n);
c[0]=1;
for(int i=1; i<=100; i++)
c[i]=c[i-1]*3;
for(int i=1; i<=n; i++)
{
scanf("%lld %lld %lld",&k,&a,&b);
printf("Case %d: ",i);
printf("%lld\n",g(k,pow(2,k)-a+1)-g(k,pow(2,k)-b));
}
return 0;
}