CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)

Posted ---学习ing---

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)相关的知识,希望对你有一定的参考价值。

As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initially contains ai stones. Two players alternate the turns. During a turn a player picks any non-empty pile and removes any positive number of stones from it. The one who is not able to make a move loses the game.

Petya and Vasya are tired of playing Nim, so they invented their own version of the game and named it the "Gambling Nim". They have n two-sided cards, one side of the i-th card has number ai written on it, while the other side has number bi. At the beginning of the game the players put all the cards on the table, each card only one of its sides up, and this side is chosen independently and uniformly. Thus they obtain a sequence c1, c2, ..., cn, where ci is equal to ai or bi. Then they take n piles of stones, with i-th pile containing exactly ci stones and play Nim. Petya takes the first turn.

Given that both players play optimally, find the probability of Petya‘s victory. Output the answer as an irreducible fraction.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of cards in the deck.

Each of the following n lines contains the description of one card, consisting of two integers ai and bi (0 ≤ ai, bi ≤ 1018).

Output

Output the answer as an irreducible fraction p / q. If the probability of Petya‘s victory is 0, print 0/1.

Examples

Input
2
1 1
1 1
Output
0/1
Input
2
1 2
1 2
Output
1/2
Input
3
0 4
1 5
2 3
Output
1/1

 

(占位,还是没有搞懂)

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 500010;
ll a[maxn],b[maxn],c[65],cnt;
#define lowbit(x) (x&-x)
int main(){
    ll n,S=0;scanf("%I64d",&n);
    for(int i=1;i<=n;++i){
        scanf("%I64d%I64d",&a[i],&b[i]);
        S^=a[i];a[i]^=b[i];
    }
    for(int i=1;i<=n;++i){
        for(int j=1;j<=cnt;++j){
            if(a[i] & lowbit(c[j])) a[i] ^= c[j];
        }if(a[i] != 0) c[++cnt] = a[i];
    }
    for(int i=1;i<=cnt;++i){
        if(S & lowbit(c[i])) S ^= c[i];
    }
    if(S != 0) puts("1/1");
    else{
        ll x = 1LL<<cnt;
        printf("%I64d/%I64d\n",x-1,x);
    }
    getchar();getchar();
    return 0;
}

 

以上是关于CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces - 662A 思路巧妙的异或

CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)

codeforces上怎么看测试数据

如何看codeforces做了多少题

codeforces上怎么看测试数据

codeforces比赛后怎么看题解和答案