题目链接:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/3566.html
把N分解成三个数相加,并且三个数亦或为0,且三个数不能为0。首先奇数的方案数为0;考虑N的二进制表示,要亦或的0,那么最高位的1要分解成低一位的两个1,同理,N中的每个1都要分解成低一位的两个1,所以会有3^num(num为N的二进制中1的个数)种方案,但是要减去3(除去其中一个数为0的情况),还要再除以6(三个数的排列只能算一种情况)。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while (t > 0)
{
t--;
int n;
cin>>n;
if (n & 1)
{
cout<<0<<endl;
continue;
}
int m = __builtin_popcount(n);
cout<<((long long)(pow(3.0,m))-3)/6<<endl;
}
return 0;
}