欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Codeforces 第 949 轮(第 2 分部 ABCD)视频演示

最编程 2024-06-02 12:31:45
...

A. Turtle and Piggy Are Playing a Game

Problem Statement

Turtle and Piggy are playing a number game.

First, Turtle will choose an integer x x x, such that l ≤ x ≤ r l \le x \le r lxr, where l , r l, r l,r are given. It’s also guaranteed that 2 l ≤ r 2l \le r 2lr.

Then, Piggy will keep doing the following operation until x x x becomes 1 1 1:

  • Choose an integer p p p such that p ≥ 2 p \ge 2 p2 and p ∣ x p \mid x px (i.e. x x x is a multiple of p p p).
  • Set x x x to x p \frac{x}{p} px, and the score will increase by 1 1 1.

The score is initially 0 0 0. Both Turtle and Piggy want to maximize the score. Please help them to calculate the maximum score.

Input

Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104). The description of the test cases follows.

The first line of each test case contains two integers l , r l, r l,r ( 1 ≤ l ≤ r ≤ 1 0 9 , 2 l ≤ r 1 \le l \le r \le 10^9, 2l \le r 1lr109,2lr) — The range where Turtle can choose the integer from.

Output

For each test case, output a single integer — the maximum score.

Example

Example

input
5
2 4
3 6
2 15
6 22
114514 1919810
output
2
2
3
4
20

Note

In the first test case, Turtle can choose an integer x x x, such that 2 ≤ x ≤ 4 2 \le x \le 4 2x4. He can choose x = 4 x = 4 x=4. Then Piggy can choose p = 2 p = 2 p=2 for 2 2 2 times. After that, x x x will become 1 1 1, and the score will be 2 2 2, which is maximized.

In the second test case, Turtle can choose an integer 3 ≤ x ≤ 6 3 \le x \le 6 3x6. He can choose x = 6 x = 6 x=6. Then Piggy can choose p = 2 p = 2 p=2, then choose p = 3 p = 3 p=3. After that, x x x will become 1 1 1, and the score will be 2 2 2, which is maximum.

In the third test case, Turtle can choose x = 12 x = 12 x=12.

In the fourth test case, Turtle can choose x = 16 x = 16 x=16.

Solution

具体见文后视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

void solve() {
	int l, r;
	cin >> l >> r;

	int x = 0;
	while ((1ll << x) <= r) x ++;
	x --;

	cout << x << endl;
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	int dt;
	
	cin >> dt;

	while (dt --)
		solve();

	return 0;
}

B. Turtle and an Infinite Sequence

Problem Statement

There is a sequence a 0 , a 1 , a 2 , … a_0, a_1, a_2, \ldots a0,a1,a2, of infinite length. Initially a i = i a_i = i ai=i for every non-negative integer i i i.

After every second, each element of the sequence will simultaneously change. a i a_i ai will change to a i − 1 ∣ a i ∣ a i + 1 a_{i - 1} \mid a_i \mid a_{i + 1} ai1aiai+1 for every positive integer i i i. a 0 a_0 a0 will change to a 0 ∣ a 1 a_0 \mid a_1 a0a1. Here, ∣ | denotes bitwise OR.

Turtle is asked to find the value of a n a_n an after m m m seconds. In particular, if m = 0 m = 0 m=0, then he needs to find the initial value of a n a_n an. He is tired of calculating so many values, so please help him!

Input

Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104). The description of the test cases follows.

The first line of each test case contains two integers n , m n, m n,m ( 0 ≤ n , m ≤ 1 0 9 0 \le n, m \le 10^9 0n,m109).

Output

For each test case, output a single integer — the value of a n a_n an after m m m seconds.

Example

Example

input
9
0 0
0 1
0 2
1 0
5 2
10 1
20 3
1145 14
19198 10
output
0
1
3
1
7
11
23
1279
19455

Note

After 1 1 1 second, [ a 0 , a 1 , a 2 , a 3 , a 4 , a 5 ] [a_0, a_1, a_2, a_3, a_4, a_5] [a0,a1,a2,a3,a4,a5] will become [ 1 , 3 , 3 , 7 , 7 , 7 ] [1, 3, 3, 7, 7, 7] [1,3,3,7,7,7].

After 2 2 2 seconds, [ a 0 , a 1 , a 2 , a 3 , a 4 , a 5 ] [a_0, a_1, a_2, a_3, a_4, a_5] [a0,a1,a2,a3,a4,a5] will become [ 3 , 3 , 7 , 7 , 7 , 7 ] [3, 3, 7, 7, 7, 7] [3,3,7,

上一篇: 国际标准 SHARE78 七级灾难备份程序 (I)

下一篇: 2022 中国元数据白皮书发布,引导行业驶入快车道