Seventh annual Triple Nim of Shandong Province (to be sorted by law)

Source: Internet
Author: User
Tags printf time limit
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;
}







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.