NC14371. Numbers
描述
输入描述
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 ≤ n < 101000,1 ≤ m < 10100)It is guaranteed that the sum of n the length of does not exceed 20000.
输出描述
For each test case, output an integer denoting the minimum value of their bitwise or.
示例1
输入:
5 3 1 3 2 3 3 10000 5 1244 10
输出:
3 3 1 2000 125
Python3 解法, 执行用时: 102ms, 内存消耗: 6964K, 提交时间: 2021-11-18 15:01:02
T = int(input()) for _ in range(T): n,m = map(int,input().split()) ans=0 t=1 while t<n:t<<=1 while n!=0: if (t-1)*m<n: tt=min(m,n//t) n-=tt*t ans|=t t>>=1 print(ans)