大佬真的强!!https://blog.csdn.net/u014800748/article/details/45225881
#include<cstdio>
#include<cstring>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
const int MAXN = 70;
int mod[MAXN], n, k;
ll d[MAXN][MAXN][MAXN*2];
ll dfs(int cur, int num, int MOD)
{
if(cur == 0)
{
if(num > 0) return 0;
return d[cur][num][MOD] = (MOD % k == 0);
}
if(d[cur][num][MOD] != -1) return d[cur][num][MOD];
ll& ans = d[cur][num][MOD];
ans = dfs(cur - 1, num, MOD);
if(num > 0) ans += dfs(cur - 1, num - 1, (MOD - mod[cur] + k) % k);
return ans;
}
void init()
{
mod[1] = 1;
REP(i, 2, MAXN)
mod[i] = (mod[i-1] << 1) % k;
}
int main()
{
int T, kase = 0;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &k);
printf("Case %d: ", ++kase);
if(k == 0 || (n & 1)) { puts("0"); continue; }
memset(d, -1, sizeof(d));
init();
printf("%lld
", dfs(n - 1, (n - 1) / 2, (k - mod[n]) % k));
}
return 0;
}