Triple NimTime limit:2000ms Memory limit:65536kb Submit statistic
problem Description
Alice and Bob is always playing all kinds of the Nim games and Alice always goes first. Here is the rule of the Nim game:
There is some distinct heaps of stones. On each turn, the players should remove at least one stone from just one heap. Both player would remove stone one after another. The player who remove the last stone of the last heap would win.
Alice always wins and Bob is very unhappy. So he decides and make a game which Alice would never win. He begins a game called "Triple Nim", which is the Nim game with three heaps of stones. He ' s good at the Nim game but bad as math. With exactly N stones, what many ways can he finish his target? Both Alice and Bob would play optimally. Input Multiple test cases. The first line contains a integer t (t <= 100000), indicating the number of test case. Each case is contains one line, an integer N (3 <= n <= 1000000000) indicating the number of stones Bob has. Output One line per case. The number of ways Bob can make Alice never win. Example Input
33614
Example Output
014
HintIn the third case, Bob can make three heaps (1,6,7), (2,5,7), (3,4,7) or (3,5,6).
Author"Wave Cup" Shandong Province Seventh annual ACM College Student Program Design contest
Test instructions: give you n a stone, divided into three piles, calculate the number of programs that pass the NIM game so that the opponent cannot win.
Idea: play the table to find regular questions, do not explain.
Reference URL: http://blog.csdn.net/huayunhualuo/article/details/51626212
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main ()
{
int T;
LL N;
scanf ("%d", &t);
while (t--)
{
scanf ("%lld", &n);
if (n%2) printf ("0\n");
else
{
int s = 0;
while (n)
{
if (n%2) s++;
n/=2;
}
ll ans = (ll (POW (3,s))-3)/6;
printf ("%lld\n", ans);
}
}
return 0;
}