Sicily 1923. Is It Nim?

1923. Is It Nim?

Constraints

Time Limit: 2 secs, Memory Limit: 32 MB

Description

  Alice and Bob play a new game again! There are N piles of stones. Each pile of stones may have different number of stones. They take turns to play, and Alice always play at the first turn.
  At each turn, the player of this turn must choose at least one and at most K piles of stones and take at least one stone away from each of them. Who take the last stone of the game will win.
  They both play optimally. But they want the game more interesting. So before the game start, Alice decide the number of stones in each pile, then Bob decide the number K.
  Now Alice has decided it, and Bob want to be the winner. How many integers can be chosen by Bob as K will lead to his winning of the game?

Input

  In the first line, there is one integer T(1<=T<=60).
  Then T test cases follow. In the first line of each test cases, there is one integer N(1<=N<=1000), the number of piles in the game. In the second line of each test case, there are N integers, a1, a2 ... an, the number of stones in each piles.(1<=ai<=10^9)

Output

  For each test case, output one line with only one integer, the number of integers that Bob can choose as K will lead to his winning of the game.

Sample Input

2
3
1 2 3
4
1 2 3 4

Sample Output

1

0

// Problem#: 1923
// Submission#: 3279535
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>
#include <string.h>
int main()
{
    int n,m,t,i,j,s[34];
    scanf("%d",&n);
    while(n--){
        memset(s,0,sizeof(s));
        scanf("%d",&m);
  for(i=0;i<m;i++){
   scanf("%d",&t);
   j=0;
         while(t!=0){    //化为二进制并将各位加到适当位置去
             s[j]+=t%2;
             t/=2;
             j++;
         } 
  }
   t=m;
  for(i=2;i<=m+1;i++)    //判断不同的i(即k)是否会导致Bob必胜
  for(j=0;j<34;j++){
   if(s[j]%i!=0){
    t--;
    break;
   }
  }
        printf("%d\n",t);
    }
    return 0;
}                                 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值