题干:

It’s time to fight the local despots and redistribute the land. There is a rectangular piece of land granted from the government, whose length and width are both in binary form. As the mayor, you must segment the land into multiple squares of equal size for the villagers. What are required is there must be no any waste and each single segmented square land has as large area as possible. The width of the segmented square land is also binary.

Input

The first line of the input is T (1 ≤ T ≤ 100), which stands for the number of test cases you need to solve.

Each case contains two binary number represents the length L and the width W of given land. (0 < L, W ≤ 2 1000)

Output

For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then one number means the largest width of land that can be divided from input data. And it will be show in binary. Do not have any useless number or space.

Sample Input

3
10 100
100 110
10010 1100

Sample Output

Case #1: 10
Case #2: 10
Case #3: 110

题目大意:

读入二进制形式的两个数,让你以二进制的形式输出他俩对应十进制数字的gcd。

解题报告:

不得不说一句,IDEA牛逼。所有功能全都自动补全出来。

AC代码:

import java.math.*;
import java.util.Scanner;
public class Main{public static void main(String[] args) {Scanner cin = new Scanner(System.in);int t;t = cin.nextInt();BigInteger a,b;for(int i = 1; i<=t; i++) {a= cin.nextBigInteger(2);b= cin.nextBigInteger(2);System.out.print("Case #" + i + ": ");System.out.println(a.gcd(b).toString(2));}}
}

【HDU - 5050 】Divided Land (Java大数,大数进制转换,大数gcd)相关推荐

  1. HDU 5050 Divided Land JAVA GCD

    题意:给出二进制表示的长方形的边长.求出一个最大的正方形,使整个长方形分成最多的正方形.输出正方形的边长,同样也要用二进制输出. 思路:很直接的就想到了,正方形的边长是长方形的两个边长的GCD.但是因 ...

  2. (大数)进制转换 —— 16、8进制转换成2进制

    (大数)进制转换 --16.8进制转2进制 16进制转2进制示例代码: #include <iostream> using namespace std; int main(){string ...

  3. Java的API进制转换

    利用Java的API进制转换 一.其他进制转十进制 1.使用Integer.parseInt()方法 2.使用Integer.valueOf()方法 二.十进制转换其他进制 1.使用Integer.t ...

  4. Java提供的进制转换

    Java提供的进制转换 Integer.toHexString(int i); //十进制转成十六进制Integer.toOctalString(int i); //十进制转成八进制Integer.t ...

  5. java函数实现进制转换与java实现八进制到十进制的转换(百练OJ:2735:八进制到十进制)

    java进制转换函数介绍:Java二进制.八进制.十进制.十六进制相互转换: 二进制转十进制 Integer.parseInt("0110", 2); 八进制转十进制 Intege ...

  6. java中的进制转换

    进制转换 首先是十进制转化为其他进制,如二进制,八进制,十六进制: 它们在java中都有专门的函数可供调用: 如:十进制转化为二进制时调用toBinaryString(); 十进制转化为八进制时调用t ...

  7. java语言编写进制转换_Java 3种方法实现进制转换

    由其他进制转换为十进制比较简单,下面着重谈一谈十进制如何化为其他进制. 1.使用Java带有的方法Integer,最简单粗暴了,代码如下 //使用java提供的方法 //但仅局限于比较常用的二进制.八 ...

  8. java里的进制转换函数_基于Java中进制的转换函数详解

    十进制转成十六进制: Integer.toHexString(int i) 十进制转成八进制 Integer.toOctalString(int i) 十进制转成二进制 Integer.toBinar ...

  9. java 数字的进制转换

    对整数进行进制转换,有现成的函数,就不需要倒着求余数了: package hdu;public class sum {public static void main(String[] args) {/ ...

  10. java中的进制转换(十进制和二进制)

    在java中有进制转换,其中有十进制,二进制,八进制,十六进制,这里主要讲的是其中的十进制和二进制. 当我们一个数要变成二进制的时候可以对它进行除二运算.就比如6的二进制.如图            ...

最新文章

  1. [linux]在使用rsync时需要注意的小细节
  2. Bean的解析与注册
  3. html中正方形列表标签属性,如何在HTML中创建带有方形项目符号的无序列表?
  4. mac os x 10.8 安装python-mysqldb
  5. Web Service/WCF 部署注意事项。
  6. 算法学习四:算法性能分析理论基础——函数增长与渐进分析
  7. error C2065: “LOAD_LIBRARY_SEARCH_SYSTEM32”: 未声明的标识符
  8. 如何通过提前Bake Docker镜像加快基础设施的启动速度
  9. 创建一个TCP服务器端通信程序的步骤
  10. SpriteKit快速入门和新时代iOS游戏开发指南
  11. 2021年CS保研经历(四):西交软院预推免、信工所三室预推免
  12. 程序员必备:那些实用的Chrome扩展程序
  13. 中国石油大学《化工原理二》第一阶段在线作业
  14. Centos6.7安装ES6.1.3
  15. 2023年会议教学庭审录像机产品分析
  16. 【深度学习】04-01-自注意力机制(Self-attention)-李宏毅老师2122深度学习课程笔记
  17. 深度学习平台——百度AI Studio线上构建
  18. iOS 图片自由裁剪
  19. Vivado18.2 PCIE ip核IO协议详细介绍
  20. python浮点数整数、小数分离,整数取整

热门文章

  1. 关于规划修编标准的问题
  2. [Leedcode][JAVA][第72题][动态规划]
  3. HTML文件可通过www进行传输,使用 zssh 进行 Zmodem 文件传输
  4. java如何保证类不被回收_垃圾回收机制保证了Java程序不会出现内存溢出。( )
  5. java jlabel里面加button_在Java Swing中通过JLabel覆盖JButton?
  6. python去重且顺序不变_Python实现嵌套列表去重方法示例
  7. html keyup事件,jquery keyup事件为什么不执行?
  8. r语言散点图_R语言 | 散点图入门:以声学元音图为例
  9. android设置多个按钮,android代码中设置两个按钮之间位置
  10. hadoop namenode启动不了_集群版hadoop安装,写给大忙人看的