8657: Simple Math 4

内存限制:128 MB 时间限制:9 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:1

题目描述

Given nonnegative integers N,L,Rand X find the maximum value of 

i=1NAi 

over all possible integer arrays A of length N satisfying

  1. A1A2AN=X, where  denotes the bitwise exclusive-or operation;
  2. ∀1iN,LAiR.

If there exists no valid array AA satisfying above requirements, output -1.

输入格式

The first line contains an integer T. (1T3000), denoting the number of test cases.

For each test case, there is a line containing integers N,L,R,X(1N1090LR1090X109).

输出格式

For each test case, output an integer in a line, denoting the answer.

输入样例 复制

1
5 890 970 768

输出样例 复制

4756