Numbers

TimeLimit:2000MS  MemoryLimit:65536KB
64-bit integer IO format:%lld
未提交 | 登录后收藏
Problem Description

DreamGrid has a nonnegative integer \(n\). He would like to divide \(n\) into \(m\) nonnegative integers \(a_1, a_2, \dots, a_m\) and minimizes their bitwise or (i.e. \(n=a_1 + a_2 + \dots + a_m\) and \(a_1 \text{ OR } a_2 \text{ OR } \dots \text{ OR } a_m\) should be as small as possible).

Input

There are multiple test cases. The first line of input contains an integer \(T\), indicating the number of test cases. For each test case:

The first line contains two integers \(n\) and \(m\) (\(0 \le n < 10^{1000}, 1 \le m < 10^{100}\)).

It is guaranteed that the sum of the length of \(n\) does not exceed \(20000\).

Output

For each test case, output an integer denoting the minimum value of their bitwise or.

Sample Input

5
3 1
3 2
3 3
10000 5
1244 10

Sample Output

3
3
1
2000
125

Author: LIN, Xi
Source: The 2017 China Collegiate Programming Contest, Qinhuangdao Site
Input
Output
SampleInput And SampleOutput
NULL
Submit
题目统计信息详细
总AC数0
通过人数0
尝试人数1
总提交量1
AC率0.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: