由异或的性质,两个数 异或和等于 当且仅当 。
所以在区间 中选择两个相同的数的 的概率:
(重合段的长度除以总个数)
#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');
}
}
}