Numbers

G - Numbers

 DreamGrid has a nonnegative integer . He would like to divide  into nonnegative integers  and minimizes their bitwise or (i.e.  and  should be as small as possible).

Input

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

The first line contains two integers  and  ().

It is guaranteed that the sum of the length of  does not exceed .

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
import java.util.Scanner;
import java.math.*;
public class Main {

	public static void main(String[] args) {
		
		Scanner reader=new Scanner(System.in);
		int t;
		t=reader.nextInt();
		BigInteger one=BigInteger.ONE;
		while(t>0){
			t--;
			BigInteger n=reader.nextBigInteger();
			BigInteger m=reader.nextBigInteger();
			BigInteger ans=BigInteger.ZERO;
			int x=n.bitLength();
			for(int i=x;i>=0;i--) {
				///应该让最高位尽量为1
				BigInteger sb=one.shiftLeft(i);///(2^k-1)*m>=n
				//System.out.print(sb+" ");
				///如果
				if(sb.subtract(one).multiply(m).compareTo(n)>=0) {
					continue;
				} else {
					ans=ans.add(sb);
					BigInteger o=n.divide(sb);
					if(o.compareTo(m)>=0) {
						n=n.subtract(m.multiply(sb));
					} else {
						n=n.mod(sb);
					}
					System.out.println(n+" "+ans+" end");
					//System.out.println(n);
					//System.out.println(ans);
					//System.out.println("end");
				}
			}
			System.out.println(ans);
		}
		reader.close();
	}

}

 

内容概要:本文档是一份基于最新Java技术趋势的实操指南,涵盖微服务架构(Spring Cloud Alibaba)、响应式编程(Spring WebFlux + Reactor)、容器化与云原生(Docker + Kubernetes)、函数式编程与Java新特性、性能优化与调优以及单元测试与集成测试六大技术领域。针对每个领域,文档不仅列出了面试中的高频考点,还提供了详细的实操场景、具体实现步骤及示例代码。例如,在微服务架构中介绍了如何利用Nacos进行服务注册与发现、配置管理,以及使用Sentinel实现熔断限流;在响应式编程部分展示了响应式控制器开发、数据库访问和流处理的方法;对于容器化,则从Dockerfile编写到Kubernetes部署配置进行了讲解。 适合人群:具有一定的Java编程基础,尤其是正在准备面试或希望深入理解并掌握当前主流Java技术栈的研发人员。 使用场景及目标:①帮助求职者熟悉并能熟练运用微服务、响应式编程等现代Java开发技术栈应对面试;②指导开发者在实际项目中快速上手相关技术,提高开发效率和技术水平;③为那些想要深入了解Java新特性和最佳实践的程序员提供有价值的参考资料。 阅读建议:由于文档内容丰富且涉及多个方面,建议读者按照自身需求选择感兴趣的主题深入学习,同时结合实际项目进行练习,确保理论与实践相结合。对于每一个技术点,不仅要关注代码实现,更要理解背后的原理和应用场景,这样才能更好地掌握这些技能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值