由异或的性质,两个数 x,yx,y 异或和等于 00 当且仅当 x=yx=y

所以在区间 x[a,b],y[c,d]x\in[a,b],y\in[c,d] 中选择两个相同的数的 x,yx,y 的概率:

min(b,d)max(a,c)+1(ba+1)×(dc+1)\dfrac{\min(b,d)-\max(a,c)+1}{(b-a+1)\times(d-c+1)}(重合段的长度除以总个数)

#include<cstdio>
#define int long long
int init(){
	char c = getchar();
	int x = 0, f = 1;
	for (; c < '0' || c > '9'; c = getchar())
		if (c == '-') f = -1;
	for (; c >= '0' && c <= '9'; c = getchar())
		x = (x << 1) + (x << 3) + (c ^ 48);
	return x * f;
}
void print(int x){
	if (x < 0) x = -x, putchar('-');
	if (x > 9) print(x / 10);
	putchar(x % 10 + '0');
}
int gcd(int x, int y){
    return y ? gcd(y, x % y) : x;
}
int mn(int x, int y){
    return x < y ? x : y;
}
int mx(int x, int y){
    return x > y ? x : y;
}
signed main(){
    int a, b, c, d;
    while (scanf("%lld%lld%lld%lld", &a, &b, &c, &d) != EOF) {
        int x = mn(b, d) - mx(a, c) + 1;
        if (x < 1) puts("0/1");
        else {
            int y = (b - a + 1) * (d - c + 1);
            int g = gcd(x, y);
            x /= g, y /= g;
            print(x), putchar('/'), print(y), putchar('\n');
        }
    }
}