题意  给你两个二进制数m,n   求他们的最大公约数  用二进制表示  0<m,n<2^1000

先把二进制转换为十进制  求出最大公约数  再把结果转换为二进制  数比較大要用到大数

import java.util.*;
import java.math.*; public class wl6_9 { static BigInteger two = BigInteger.valueOf(2), one = BigInteger.ONE,
zero = BigInteger.ZERO; static BigInteger gcd(BigInteger a, BigInteger b) {
while (!(a.mod(b).equals(zero))) {
BigInteger t = a.mod(b);
a = b;
b = t;
}
return b;
} static void bprint(BigInteger x) {
if (x.equals(zero))
return;
bprint(x.divide(two));
if (x.mod(two).equals(one))
System.out.print(1);
else
System.out.print(0);
} public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
String a, b;
for (int t = 1; t <= T; t++) {
a = in.next();
b = in.next();
int la = a.length(), lb = b.length(); BigInteger m = zero, n = zero;
for (int i = 0; i < la; ++i) {
m = m.multiply(two);
if (a.charAt(i) == '1')
m = m.add(one);
} for (int i = 0; i < lb; ++i) {
n = n.multiply(two);
if (b.charAt(i) == '1')
n = n.add(one);
}
System.out.printf("Case #%d: ", t);
bprint(gcd(m, n));
System.out.println();
}
in.close();
}
}

Divided Land

Problem Description
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 ≤ 21000)
 
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
 
Source
 

HDU 5050 Divided Land(进制转换)的更多相关文章

  1. HDU 2097 Sky数 进制转换

    解题报告:这题就用一个进制转换的函数就可以了,不需要转换成相应的进制数,只要求出相应进制的数的各位的和就可以了. #include<cstdio> #include<string&g ...

  2. Hdu 5050 Divided Land

    题目要求就是做求两个二进制数的gcd,如果是用java的话,这题很简单.但也可以用C++做,只能先给自己留下这个坑了,还在研究c++的做法. import java.math.BigInteger; ...

  3. HDU 2031 进制转换(10进制转R进制)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2031 进制转换 Time Limit: 2000/1000 MS (Java/Others)    M ...

  4. hdu 2031 进制转换(栈思想的使用)

    进制转换 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. HDU 1877 又一版 A+B(进制转换)

    看了http://lovnet.iteye.com/blog/1690276的答案 好巧妙的方法 递归实现十进制向m进制转换 #include "stdio.h" int m; v ...

  6. 进制转换,杭电0j-2031

    进制转换,杭电0j-2031原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=2031 [Problem Description] 输入一个十进制数N,将它 ...

  7. SQL Server 进制转换函数

    一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...

  8. [No000071]C# 进制转换(二进制、十六进制、十进制互转)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. JS中的进制转换以及作用

    js的进制转换, 分为2进制,8进制,10进制,16进制之间的相互转换, 我们直接利用 对象.toString()即可实现: //10进制转为16进制 ().toString() // =>&q ...

随机推荐

  1. http://www.shengshiyouxi.com

    android从Linux系统启动有4个步骤:   (1) init进程启动   (2) Native服务启动   (3) System Server,Android服务启动   (4) Home启动 ...

  2. [置顶] Android常用适配器控件

    Android常用适配器控件 列表控件用于显示数据集合,Android不是使用一种类型的控件管理显示和数据,而是将这两项功能分布用列表控件和适配器来实现.列表控件扩展了android.widget.A ...

  3. SE 2014年5月27日

    R1模拟总部,R2 与R3模拟分部 如图配置 要求使用 GRE over IPSec VPN 主模式,启用动态路由协议rip使得总部与两分部内网可相互通讯,但要求分部用户数据流不允许互通! 步骤: 1 ...

  4. MooTools,jQuery库的一些比对

    jQuery与MooTools库的一些比对   今天就我自己的一些认识比对下这两个JS框架,更多的是希望大家能够对MooTools这个JS框架有更多的认识.毕竟,大多数从事web前端的人对上手容易的j ...

  5. java模拟浏览器包selenium整合了htmlunit,火狐浏览器,IE浏览器,opare浏览器驱

    //如果网页源码中有些内容是js渲染过来的,那你通过HttpClient直接取肯定取不到,但是这些数据一般都是通过异步请求传过来的(一般都是通过ajax的get或者post方式).那么你可以通过火狐浏 ...

  6. 祖国版Solowheel!IPS103 独轮思维车 - 三个月体验报告

    http://tieba.baidu.com/f?kz=2308652773&mo_device=1

  7. Java自学资料——线程

    [转]传智播客成都java培训中心学员笔记. 线程: static int MAX_PRIORITY 线程能够具有的最高优先级. static int MIN_PRIORITY 线程能够具有的最低优先 ...

  8. 怎样使用jlink一键烧录整个flash Hi3518 a c e Hi3515 Hi3512

    以jlink烧录3515为例: 1\在jlink安装文件夹"C:\Program Files\SEGGER\JLinkARM_V426b"建立批处理文件"HI3515烧写 ...

  9. cocos2D-x 3.5 引擎解析之--引用计数(Ref),自己主动释放池(PoolManager),自己主动释放池管理器( AutoreleasePool)

    #include <CCRef.h> Ref is used for reference count manangement. If a classinherits from Ref. C ...

  10. Windows Phone开发(48):不可或缺的本地数据库

    原文:Windows Phone开发(48):不可或缺的本地数据库 也许WP7的时候,是想着让云服务露两手,故似乎并不支持本地数据库,所有数据都上传上"云"数据库中.不过呢,在SD ...