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

代码:

import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Scanner; public class Main { public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner str = new Scanner(System.in);
int T;
T=str.nextInt();
int i=1; for(i=1;i<=T;i++)
{
String st,st1;
st=str.next();
st1=str.next();
BigInteger a=new BigInteger(st,2);
BigInteger b=new BigInteger(st1,2);
BigInteger c=a.gcd(b);
System.out.println("Case #"+i+": "+c.toString(2)); } } }

HDU - 5050 (大数二进制gcd)的更多相关文章

  1. hdu 5050 大数

    http://acm.hdu.edu.cn/showproblem.php?pid=5050 大数模板最大公约数 信kuangbin,能AC #include <cstdio> #incl ...

  2. HDU 5050

    http://acm.hdu.edu.cn/showproblem.php?pid=5050 大数gcd import java.io.* ; import java.math.* ; import ...

  3. 【数论】二进制GCD

    二进制GCD     GCD这种通用的算法相信每个OLER都会 ,辗转相除,代码只有四行 : int GCD(int a,int b){ if(b==0) return a; return GCD(b ...

  4. hdu 5869 区间不同GCD个数(树状数组)

    Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  5. hdu 5656 CA Loves GCD(n个任选k个的最大公约数和)

    CA Loves GCD  Accepts: 64  Submissions: 535  Time Limit: 6000/3000 MS (Java/Others)  Memory Limit: 2 ...

  6. hdu 4983 Goffi and GCD(数论)

    题目链接:hdu 4983 Goffi and GCD 题目大意:求有多少对元组满足题目中的公式. 解题思路: n = 1或者k=2时:答案为1 k > 2时:答案为0(n≠1) k = 1时: ...

  7. 二进制GCD算法解析

    UPD 2018.3.30 这个好像就是更相减损术的样子emmm UPD 2018.5.22 好像不是更相减损术而是叫Stein算法的样子emmm 蒟蒻来做个二进制GCD笔记. 为什么要写这个东西呢, ...

  8. HDU 4983 Goffi and GCD(数论)

    HDU 4983 Goffi and GCD 思路:数论题.假设k为2和n为1.那么仅仅可能1种.其它的k > 2就是0种,那么事实上仅仅要考虑k = 1的情况了.k = 1的时候,枚举n的因子 ...

  9. 二进制GCD

    目录 写在前面 具体实现: Code 写在前面 全程抄书 想要进一步提高求 \(\gcd\) 的效率,可以通过不断去除因子 \(2\) 来降低常数,这就是"二进制 \(\gcd\) &quo ...

随机推荐

  1. Jquery异步

    一.Jquery向aspx页面请求数据$("#Button1").bind("click", function () { $.ajax({ type: &quo ...

  2. 616. Add Bold Tag in String加粗字符串

    [抄题]: Given a string s and a list of strings dict, you need to add a closed pair of bold tag <b&g ...

  3. 面试题:J2EE中web.xml配置文件详解 背1

    一.web.xml是什么 web.xml学名叫部署描述符文件,是在Servlet规范中定义的,是Web应用的配置文件,是Web应用的基础. 二.web.xml加载流程 总的来说:ServletCont ...

  4. Part7-时钟初始化_lesson1

    1.概念解析 1.1时钟脉冲信号 1.2时钟脉冲频率 1.3时钟源(提供时钟脉冲信号) a.晶振 b.锁相环PLL 2.时钟体系 2440: 晶振的频率.时钟体系有多少个PLL.这些PLL分别产生了哪 ...

  5. bootstrap页面效果图

    <!DOCTYPE html><html lang="zh-cn"><head><meta charset="utf-8&quo ...

  6. App性能测试工具使用说明-MobilePerformance

    一. 环境搭建 安装Android SDK 1.6或者1.7版本均可,建议1.7,环境变量的配置,Java SDK的安装很简单,不赘述了. 安装SDK 1.安装Android SDK: 2.安装完毕后 ...

  7. (函数分治法)实现pow函数(x的y次方幂)

    题目:实现pow函数. 题目分析:因为一个一个乘,循环太大,参考矩阵连乘问题:对于n=4的话,可以得出x的平方,然后平方与平方相乘.节省计算次数.对于偶数的幂,只要x的平方多次递归调用即可:对于奇数的 ...

  8. (转)Asp.Net生命周期系列三

    原文地址:http://www.cnblogs.com/skm-blog/p/3178862.html 上文讲到了HttpRunTime主要做了三个事情,我们先回忆一下. 第一:雇佣了项目经理(Htt ...

  9. 关于在jeecms中css,图片,html,模板是如何组装成——part1

    先从HTML入手:index.html <!DOCTYPE HTML> <html> <meta name="viewport" content=&q ...

  10. C#分布式存储演练(提供项目下载)

    C#简单的演练了一下分布式的存储,学习fastdns的结构,Client向ProcessCenter请求Storage的服务,然后上传文件. 分布式服务就是多个服务器作为客户端互相[配合],要中心化就 ...