F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Simple Math 4

Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 106    Accepted Submission(s): 32


Problem Description
Given nonnegative integers $N,L,R$ and $X$, find the maximum value of $\sum_{i=1}^N A_i$ over all possible integer arrays $A$ of length $N$ satisfying

<ol>
<li> $ A_1 \oplus A_2 \oplus \dots \oplus A_N = X$, where $\oplus$ denotes the bitwise exclusive-or operation; </li>
<li> $\forall 1 \le i \le N$, $L \le A_i \le R$. </li>
</ol>

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

Input
The first line contains an integer $T$. ($1 \le T \le 3000$), denoting the number of test cases.

For each test case, there is a line containing integers $N,L,R,X(1 \leq N \leq 10^9$, $0 \leq L \leq R \le 10^9$, $0 \leq X \leq 10^9)$.
 

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

Sample Input
1 5 890 970 768
 

Sample Output
4756
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2025-04-01 07:25:57, Gzip enabled