HDU - 5050 (大数二进制gcd)
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)的更多相关文章
- hdu 5050 大数
http://acm.hdu.edu.cn/showproblem.php?pid=5050 大数模板最大公约数 信kuangbin,能AC #include <cstdio> #incl ...
- HDU 5050
http://acm.hdu.edu.cn/showproblem.php?pid=5050 大数gcd import java.io.* ; import java.math.* ; import ...
- 【数论】二进制GCD
二进制GCD GCD这种通用的算法相信每个OLER都会 ,辗转相除,代码只有四行 : int GCD(int a,int b){ if(b==0) return a; return GCD(b ...
- hdu 5869 区间不同GCD个数(树状数组)
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- hdu 5656 CA Loves GCD(n个任选k个的最大公约数和)
CA Loves GCD Accepts: 64 Submissions: 535 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 2 ...
- hdu 4983 Goffi and GCD(数论)
题目链接:hdu 4983 Goffi and GCD 题目大意:求有多少对元组满足题目中的公式. 解题思路: n = 1或者k=2时:答案为1 k > 2时:答案为0(n≠1) k = 1时: ...
- 二进制GCD算法解析
UPD 2018.3.30 这个好像就是更相减损术的样子emmm UPD 2018.5.22 好像不是更相减损术而是叫Stein算法的样子emmm 蒟蒻来做个二进制GCD笔记. 为什么要写这个东西呢, ...
- HDU 4983 Goffi and GCD(数论)
HDU 4983 Goffi and GCD 思路:数论题.假设k为2和n为1.那么仅仅可能1种.其它的k > 2就是0种,那么事实上仅仅要考虑k = 1的情况了.k = 1的时候,枚举n的因子 ...
- 二进制GCD
目录 写在前面 具体实现: Code 写在前面 全程抄书 想要进一步提高求 \(\gcd\) 的效率,可以通过不断去除因子 \(2\) 来降低常数,这就是"二进制 \(\gcd\) &quo ...
随机推荐
- Ubuntu 复制 拷贝和自适应屏幕
ubuntu 16.04安装vmtools实测无效!!!!!!11 1.解决VMware workstation与主机的粘贴.复制.文件拖拽问题. 2.解决VMware workstations中Ub ...
- 多重if else和switch case的区别
int main(void) { int id; scanf_s("%d",&id); switch(id) { case 2: printf("John\n&q ...
- Linux gtypist
一.简介 Typist (gtypist)是一个打字练习软件,用来提升打字的速度. 二.安装 1)源码方式 http://ftp.gnu.org/gnu/gtypist/ 三.使用 http: ...
- MySQL中having与where
having与where区别: where中不可以用聚合函数(条件字段是未分组中的字段),having中可以用聚合函(条件字段是分组后字段).不过这里也很好理解,SQL语句在执行是先执行select ...
- TP5多入口设置
今天在用tp5做项目的时候发现,前台是可以绑定默认到index模块的,但是后台不好弄,于是查了一下手册,按照手册上说的,复制了index.php改为admin.php,作为后台的入口文件,于是域名/a ...
- jqGrid查询案例(实用)
var ThisTime = getNowFormatDate(); //加载表格 function GetGrid() { var selectedRowIndex = 0; var $gridTa ...
- QT开发环境
代码实现界面和槽 代码实现界面和槽 在上述工程的dialog.h中添加如下加黑代码: 加入头文件: #include <QLabel> #include <QLineEdit> ...
- 代理(Proxy)模式
代理模式(Proxy):为其他对象提供一种代理以控制对这个对象的反问. * 抽象主题角色(Subject):声明了真实主题和代理主题的共同接口,这样一来在任何使用真实主题的地方都可以使用代理主题. * ...
- SOA-WebService
一.创建Web服务方法 在项目上右击选择新建项>>Web服务(ASMX),并命名,如MyWebService.asmx 二.注意事项 所有需要外界调用的方法上端均需增加特性[WebMeth ...
- .net core Task.Result Wait等造成502
这两天公众号项目上线,刚开始项目运行没什么问题,但几天之后,访问量激增,服务器崩溃了,每次请求都返回502,一脸懵逼,无从下手,赶紧开日志里的BUG,拿出来一个个改,BUG都改完之后,没有明显的效果, ...