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. win10 Kinect2 Visualstudio2015 opencv3环境搭建

    1.下载kinect SDK ( Kinect for Windows SDK 2.0 ):  https://www.microsoft.com/en-us/download/details.asp ...

  2. 19-字符串匹配(kmp || substr,find)

    链接:https://www.nowcoder.com/acm/contest/77/C来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...

  3. Docker学习笔记_网上资源参考

    Docker学习,网上资源参考 1.菜鸟教程:                                                        http://www.runoob.com ...

  4. jQuery--修改表单数据并提交

    目的: ​点击'编辑',弹出对话框,修改数据. 主要知识点: prevAll(),获取同级别本元素前面的所有元素. 代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...

  5. 使用 insertBefore 和insertAfter,在指定位置追加与删除元素

    来自于<sencha touch 权威指南> ----------------------------------- 除 append 和 overwrite 外,还可以使用 insert ...

  6. js加载页面使用execute_script选定加载位置

    #由于js逐步加载页面,存在未显示的网页无法加载源码 from selenium import webdriver driver = webdriver.Firefox() init_element ...

  7. My First JS Page

    哗啦啦~我的处女作终于浮出水面了^ ^值得高兴一下,虽然参考了人家的代码.给我的感觉JS就是用来实现动态网页的,比如说弹出一个框框,然后调用JS,返回些东西. 1.打开新写好的页面a.html,弹出了 ...

  8. React项目中的registerServiceWorker的作用

    在公司的React前端项目中,发现有一个registerServiceWorker.js文件, 很久都没弄明白这个文件是干什么用的,查询了一些资料后,了解了一些 service worker是在后台运 ...

  9. LightOJ 1038 Race to 1 Again (概率DP,记忆化搜索)

    题意:给定一个数 n,然后每次除以他的一个因数,如果除到1则结束,问期望是多少. 析:概率DP,可以用记忆公搜索来做,dp[i] = 1/m*sum(dp[j] + 1) + 1/m * (dp[i] ...

  10. 编写高质量代码改善C#程序的157个建议——建议58:用抛出异常代替返回错误代码

    建议58:用抛出异常代替返回错误代码 CLR异常机制的优点: 正常控制流会被立即中止,无效值或状态不会在系统中继续传播. 提供了统一的处理错误的方法. 提供了在构造函数.操作符重载及属性中报告异常的遍 ...