hdu 5050 Divided Land

题目入口hdu 5050

题目大意:对于给出的两个二进制大数(范围为( 0 , 2^1000 ]),计算出其最大公约数,并以二进制格式输出。

编者小语:原本是想用 C 实现的,奈何不会那些个繁复动作,只好试着用 Java 实现,身边有小伙伴会用 Java 写大数题,感觉挺腻害的。于是下了 eclipse ,找了些资料试着写下,看看代码确实挺简洁的,毕竟函数工具是现成的,只要知道怎么调用就行了。 待会儿得把网上找来的大数类的函数工具贴一下,备忘~

参考代码

import java.io.*;  
import java.math.BigInteger;  
import java.util.*;

@SuppressWarnings("unused")
public class Main 
{

	public static void main(String[] args)
	{
		@SuppressWarnings("resource")
		Scanner cin=new Scanner(System.in);
		int T=cin.nextInt();
		int cnt=1;
		while(T>0)
		{
			String n=cin.next();
			String m=cin.next();
			BigInteger ans1=new BigInteger(n,2);
			BigInteger ans2=new BigInteger(m,2);
			BigInteger ans=ans1.gcd(ans2);
			System.out.print("Case #"+cnt+": ");
			System.out.println(ans.toString(2));
			cnt++;
			T--;
		}
	}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值