PDP-38 (2026) - Phase A - 4 (bqueries)
View as PDFBinary Queries
Tired of carrying boxes from Giannis's warehouse back to his own, Takis sat down at his desk to try to come up with a problem for Phase of the Greek Olympiad in Informatics (PDP).
While experimenting on paper, he noticed that
, where
is the bitwise operation
(see here for its definition). He found this very interesting and wanted to know how often the bitwise
of two numbers is equal to one of them.
Specifically, he has queries of the form
, where
and
are non-negative integers and
.
The answer to such a query is the number of pairs
such that
and
, for which the following holds:
Answer Takis's queries while he looks for interesting problems for Phase as well.
Problem
Write a program in C++ that reads the input data from the file bqueries.in and prints the results to the file bqueries.out.
Input Files (bqueries.in)
The first line contains an integer : the number of Takis's queries.
The next
lines each contain two integers
and
: the
-th query.
Output Files (bqueries.out)
The output must consist of lines, each containing an integer: the answer to the
-th query.
Sample Input - Output Files:
Input:
2
3 7
777777 888888
Output:
11
75497532
Explanation:
For the first query, the pairs of integers from
to
inclusive that satisfy the requirement are:
,
,
,
,
,
,
,
,
,
and
.
Constraints
Subtasks:
- (13 points)
,
, for every
(where
).
- (16 points)
,
, for every
(where
).
- (21 points) For every
(where
), there exist positive integers
,
such that
and
.
- (27 points)
, for every
(where
).
- (23 points) There are no further constraints.
Notes:
- Formatting: In both the input and the output, each line ends with a
newlinecharacter. - Maximum execution time:
sec.
- Maximum available memory:
MB.
Warning: The answer may exceed and, in general, you may need to perform operations with numbers larger than those that can be represented by the basic
int type.
Also, make sure to read the input and print the output efficiently in problems that require it.
Comments