山东第7届省赛 G Triple Nim 找规律

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.

输入

 Multiple test cases. The first line contains an integer T (T <= 100000), indicating the number of test case. Each case contains one line, an integer N (3 <= N <= 1000000000) indicating the number of stones Bob have.

输出

 One line per case. The number of ways Bob can make Alice never win.

示例输入

3
3
6
14

示例输出

0
1
4

提示

 In the third case, Bob can make three heaps (1,6,7), (2,5,7), (3,4,7) or (3,5,6).

来源

  “浪潮杯”山东省第七届ACM大学生程序设计竞赛

示例程序

给你一个数N 分成3个数使得这3个数异或值为0
ACcode:
#include 
#define ll long long 
using namespace std;
int main(){
    int n,loop,cnt=1;
    scanf("%d",&loop);
    while(loop--){
        scanf("%d",&n);
        if(n<6||n&1)puts("0");
        else {
            int ans=__builtin_popcount(n);
            printf("%lld\n",((ll)pow(3.0,ans)-3)/6);
        }
    }
    return 0;
}


你可能感兴趣的:(省赛真题,递推)