We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
count1 = [[0] * MAXN for _ in range(MAX_VALUE)] # (x, y) stored number of pair (i, j) which i^j == x && i >= x && j >= y
count2 = [0] * MAXN # value at x stored number of pair (i, j) which i >= x && j >= x
abcd = [a, b, c, d]
abcd.sort()
for i in range(1, abcd[0] + 1):
for j in range(i, abcd[1] + 1):
count1[i ^ j][j] += 1
count2[j] += 1
for i in range(MAX_VALUE):
for j in range(1, MAXN):
count1[i][j] += count1[i][j - 1]
for i in range(1, MAXN):
count2[i] += count2[i - 1]
totalCombination = 0
count = 0
for i in range(1, abcd[2] + 1):
for j in range(i, abcd[3] + 1):
totalCombination += count2[i]
count += count1[i ^ j][i]
return totalCombination - count
Reading input and writing output
if name == "main":
import os
fptr = open(os.environ['OUTPUT_PATH'], 'w')
Beautiful Quadruples
You are viewing a single comment's thread. Return to all comments →
def beautifulQuadruples(a, b, c, d): MAX_VALUE = 5000 MAXN = 3001
Reading input and writing output
if name == "main": import os fptr = open(os.environ['OUTPUT_PATH'], 'w')