Live2d Test Env

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

 

(占位,还是没有搞懂)

 有点像线性基,但是这个是不去重的,而且用的是lowbit~~~晕啦。

#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;
}

 

posted @ 2018-10-01 21:08  nimphy  阅读(325)  评论(0编辑  收藏  举报