题解 | 异或

异或

https://www.nowcoder.com/practice/4c788d7749874d4387843fe2ff99a2f3

异或为0只有当两数相等的情况下才行,所以只需求(两数交集大小)//(a数组大小)*(b数组大小),用gcd求出最简表达式即可

from math import gcd
import sys
input = lambda : sys.stdin.read().strip()
op = list(map(int,input().split()))
for i in range(0,len(op),4):
    a,b,c,d = op[i:i+4]
    if c > b or d < a :
        print("0/1")
    else :
        l = max(a,c);r=min(b,d)
        n,m = (b-a+1)*(d-c+1),abs(r-l+1)
        c = gcd(n,m)
        print(f"{m//c}/{n//c}")

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务