Triple Nim
Time Limit: 2000MS Memory limit: 65536K
题目描述
Alice and Bob are always playing all kinds of Nim games and Alice always goes first. Here is the rule of Nim game:
There are some distinct heaps of stones. On each turn, two players should remove at least one stone from just one heap. Two player will remove stone one after another. The player who remove the last stone of the last heap will win.
Alice always wins and Bob is very unhappy. So he decides to make a game which Alice will never win. He begins a game called “Triple Nim”, which is the Nim game with three heaps of stones. He’s good at Nim game but bad as math. With exactly N stones,
how many ways can he finish his target? Both Alice and Bob will play optimally.
输入
输出
示例输入
3
3
6
14
示例输出
0
1
4
提示
来源
题意
#include"stdio.h" #include"string.h" #include<iostream> using namespace std; long long s1(long long int n) //求一个数二进制1的个数 { long long s=0; while(n>>=1) if(n&1)++s; return s-1; } long long f[30]= {1}; void init() //打表 { for(int i=1; i<30; i++) f[i]=f[i-1]*3+1; } int main() { int N; init(); cin>>N; while(N--) { long long int n; cin>>n; if(n&1)printf("0\n"); else { long long int dd=s1(n)-1; cout<<f[dd]<<endl; } } return 0; }