【HDU - 5050 】Divided Land (Java大数,大数进制转换,大数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

题目大意:

  读入二进制形式的两个数,让你以二进制的形式输出他俩对应十进制数字的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));}}
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440501.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java重载和重写6_深入理解Java中的重写和重载

深入理解Java中的重写和重载重载(Overloading)和重写(Overriding)是Java中两个比较重要的概念。但是对于新手来说也比较容易混淆。本文通过两个简单的例子说明了他们之间的区别。定义重载简单说&#xff0c;就是函数或者方法有同样的名称&#xff0c;但是参数列表不相同的情形&…

【Gym - 101608G】WiFi Password (区间或,线段树 或 按位处理+尺取 或 二分)

题干&#xff1a; Just days before the JCPC, your internet service went down. You decided to continue your training at the ACM club at your university. Sadly, you discovered that they have changed the WiFi password. On the router, the following question wa…

java框架讲解ppt_经典框架spring介绍课件.ppt

Wepull Information Service Spring-javaEE的春天 预习检查 根据你的理解&#xff0c;“依赖注入”是什么&#xff1f; 根据你的理解&#xff0c;谈谈“依赖注入”适于在项目中应用吗&#xff1f; 你理解的“面向方面编程(AOP)”是什么样的&#xff1f; Spring框架的内容和作用…

python 协程池gevent.pool_进程池\线程池,协程,gevent

目录1. 进程池与线程池2. 协程3. gevent4. 单线程下实现并发的套接字通信首先写一个基于多线程的套接字服务端:from socket import *from threading import Threaddef comunicate(conn):while True: # 通信循环try:data conn.recv(1024)if len(data) 0: breakconn.send(data.…

【ZOJ - 3963】Heap Partition (STLset,二叉树的性质,构造,贪心,思维)

题干&#xff1a; A sequence S {s1, s2, ..., sn} is called heapable if there exists a binary tree Twith n nodes such that every node is labelled with exactly one element from the sequence S, and for every non-root node si and its parent sj, sj ≤ si and j…

java poi 3.13_Java 读取Excl文件 (poi-3.13)

最近做项目遇到了读取Excel数据到数据库做数据的初始化。于是找一个。发现(poi-3.13)可以解决问题。可以解析两种格式(xlsx和xls)以下是实现的步骤1.下载poi3.13包&#xff0c;地址(http://poi.apache.org/download.html#POI-3.13)2.学习APi。接下来是还是demo来说明问题吧&…

【CodeChef - CLIQUED 】Bear and Clique Distances(建图,缩点技巧,思维)

题干&#xff1a; 解题报告&#xff1a; 主要就是在于怎么处理那个前K个点&#xff1a;组成一个团。换句话说&#xff0c;缩成一个点。先直接当成每个点多了k条边来处理&#xff0c;T了。想想也是啊&#xff0c;要是K1e5&#xff0c;那就是1e10条边了。。刚开始尝试了半天缩点&…

【HDU - 5649】DZY Loves Sorting(线段树,区间更新区间查询,思维,01缩数变换,线段树分割)

题干&#xff1a; DZY has a sequence a[1..n]a[1..n]. It is a permutation of integers 1∼n1∼n. Now he wants to perform two types of operations: 0lr0lr: Sort a[l..r]a[l..r] in increasing order. 1lr1lr: Sort a[l..r]a[l..r] in decreasing order. After doin…

php错误403_phpstudy访问文件报错403/Forbidden解决办法

使用phpstudy访问WWW目录下的文件时&#xff0c;浏览器提示Forbidden错误&#xff0c;没有访问权限。我在网上搜索了喝多资料以及本人亲自尝试过后&#xff0c;总结了一下两种方法。方法一&#xff1a;打开phpStudy&#xff0c;点击按键“其他选项菜单”>找到phpStudy配置&g…

【CodeForces - 294B】Shaass and Bookshelf(枚举,贪心,思维,组内贪心组间dp)

题干&#xff1a; Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelfs dimensions to be as small as possible. The thickness of the i-th book is ti and its pages width is equal to wi. The thickness of each book is eith…

mac php开发集成环境,MAC OS X下php集成开发环境mamp

之前苦于mac上搭建本地服务器之艰辛&#xff0c;找寻好久都没找到一款类似windows上集成的本地服务器环境&#xff0c;诸如phpstudy&#xff0c;xampp,appserv,虽说xampp也有mac版&#xff0c;但不知为何不是Apache启动不了&#xff0c;这里小编为大家分享了MAC OS X 下php集成…

知识点总结vector创建二维数组

vector构造函数通常含有两个参数 原型如下&#xff1a; vector( size_type num, const TYPE &val ); 数量(num)和值(val) - 构造一个初始放入num个值为val的元素的Vector方法1&#xff1a; #include <iostream> #include<vector> #include<algorithm&…

php获取手机目录,php如何获取手机型号

手机App中判断平台&#xff0c;可以根据$_SERVER[HTTP_USER_AGENT]中的内容来判断浏览器类型或手机平台。(推荐学习&#xff1a;PHP编程从入门到精通)iPhone UA&#xff1a;Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, l…

【CodeForces - 920E】Connected Components? (dsu,补图连通块,STLset+map,bfs 或bitset)

题干&#xff1a; You are given an undirected graph consisting of n vertices and edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of vertices…

php获取post全部数据,PHP获取POST数据的几种方法汇总_PHP教程

PHP获取POST数据的几种方法汇总本文给大家汇总介绍了PHP获取POST数据的几种常用方法&#xff0c;这里分享给大家&#xff0c;有需要的小伙伴来参考下吧。一、PHP获取POST数据的几种方法方法1、最常见的方法是&#xff1a;$_POST[‘fieldname’];说明&#xff1a;只能接收Conten…

yiilite.php,缓存 - yii在哪些情况下可以加载yiilite.php?

yii权威指南上说&#xff0c;在开启apc缓存的情况下&#xff0c;可以加载yiilite.php提升性能。我有以下几点疑问&#xff1a;1.开启apc缓存的情况下&#xff0c;引入yiilite.php能提升性能的原因是因为缓存了opcode的关系么&#xff1f;2.使用其他缓存服务缓存opcode的情况下&…

【HDU - 1024 】Max Sum Plus Plus (dp及优化,最大m子段和)

题干&#xff1a; Now I think you have got an AC in Ignatius.Ls "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem. Given a consecutive number sequence…

java 内部类 菜鸟编程,java中的匿名内部类

匿名内部类也就是没有名字的内部类正因为没有名字&#xff0c;所以匿名内部类只能使用一次&#xff0c;它通常用来简化代码编写但使用匿名内部类还有个前提条件&#xff1a;必须继承一个父类或实现一个接口实例1:不使用匿名内部类来实现抽象方法abstract class Person {public …

【牛客 - 551F】CSL 的神奇序列(推公式,猜结论,母函数)

题干&#xff1a; 链接&#xff1a;https://ac.nowcoder.com/acm/contest/551/F 来源&#xff1a;牛客网 题目描述 CSL 有一个神奇的无穷实数序列&#xff0c;他的每一项满足如下关系&#xff1a; 对于任意的正整数 n &#xff0c;有 , 并且 。 CSL 很清楚这样的序列是唯…

java什么时候创建进程,Java创建进程

Java创建进程1 进程的概念 11.1 进程的概念 11.2 进程的特征 11.3 进程与线程区别 12 进程的创建 12.1 JAVA进程的创建 12.1.1 ProcessBuilder 22.1.2 Runtime 32.1.3 Process 42.2 实例 52.2.1 创建子进程 52.2.2 进程阻塞问题 72.2.3 在java中执行java程序 111 进程的概念1.1…