JIJ 编程竞赛 2026(第 476 场 AtCoder Beginner Contest)
G
递增的 Popcount
Increasing Popcount
AtCoder
⌀ 2477
原题
← F→

递增的 PopcountAI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given positive integers $L$ and $R$ satisfying $L\le R$.

给定满足 $L\le R$ 的正整数 $L$ 和 $R$。AI (CI翻译)

A sequence of positive integers $A=(A_L,A_{L+1},\ldots,A_R)$ of length $R-L+1$ satisfying the following condition is called a good integer sequence:

长度为 $R-L+1$ 的正整数序列 $A=(A_L,A_{L+1},\ldots,A_R)$,如果满足以下条件,则称为良好整数序列:AI (CI翻译)

  • For every pair of integers $(i,j)$ satisfying $L\le i < j\le R$, if $A_i = A_j$, then $\operatorname{popcount}(i)<\operatorname{popcount}(j)$.
  • 对于所有满足 $L\le i < j\le R$ 的整数对 $(i,j)$,若 $A_i = A_j$,则必须有 $\operatorname{popcount}(i)<\operatorname{popcount}(j)$。
AI (CI翻译)

Find the minimum value of $\max(A_L,A_{L+1},\ldots,A_R)$ over all good integer sequences $A=(A_L,A_{L+1},\ldots,A_R)$.

请在所有良好整数序列 $A=(A_L,A_{L+1},\ldots,A_R)$ 中,求 $\max(A_L,A_{L+1},\ldots,A_R)$ 的最小值。AI (CI翻译)

You are given $T$ test cases; solve each of them.

给定 $T$ 组测试用例,请分别求解。AI (CI翻译)

What is $\operatorname{popcount}$? For a non-negative integer $x$, $\operatorname{popcount}(x)$ is the number of $1$'s when $x$ is written in binary. More precisely, when a non-negative integer $x$ satisfies $\displaystyle x=\sum _ {i=0} ^ \infty b _ i2 ^ i\ (b _ i\in\lbrace0,1\rbrace)$, $\displaystyle\operatorname{popcount}(x)=\sum _ {i=0} ^ \infty b _ i$. For example, $13$ written in binary is 1101, so $\operatorname{popcount}(13)=3$.

什么是 $\operatorname{popcount}$?对于非负整数 $x$,$\operatorname{popcount}(x)$ 表示 $x$ 的二进制表示中 $1$ 的个数。更准确地说,若非负整数 $x$ 满足 $\displaystyle x=\sum _ {i=0} ^ \infty b _ i2 ^ i\ (b _ i\in\lbrace0,1\rbrace)$,则 $\displaystyle\operatorname{popcount}(x)=\sum _ {i=0} ^ \infty b _ i$。例如,$13$ 的二进制表示为 1101,因此 $\operatorname{popcount}(13)=3$。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1\le T\le 10^4$
  • $1\le L \le R\le 10^{18}$
  • All input values are integers.
  • $1\le T\le 10^4$
  • $1\le L \le R\le 10^{18}$
  • 输入的所有数值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
AI (CI翻译)

Each test case is given in the following format.

每组测试用例按以下格式给出。AI (CI翻译)

L R

L R
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output $T$ lines.

输出 $T$ 行。AI (CI翻译)

The $i$-th line $(1\le i\le T)$ should contain the answer for the $i$-th test case $\text{case}_i$.

第 $i$ 行 $(1\le i\le T)$ 应包含第 $i$ 组测试用例 $\text{case}_i$ 的答案。AI (CI翻译)

样例

Input #1
5
3 6
1 1
2 15
100 10000000
514284786278117031 620546740167642909
Output #1
3
1
6
1636985
11375123021856567
Consider the first test case. $(A_3,A_4,A_5,A_6)=(1,2,2,3)$ is a good integer sequence, and $\max(A_3,A_4,A_5,A_6)=3$. There is no good integer sequence with $\max(A_3,A_4,A_5,A_6) < 3$, so output $3$ on the first line.
题目信息
题号
abc476_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。