JAVA大数

http://acm.fzu.edu.cn/problem.php?pid=2036

fzu  2036 Log Calculator

import java.util.Scanner;
import java.math.BigInteger;
import java.math.BigDecimal;
import java.math.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		BigDecimal a, b, ans, c;
		c = BigDecimal.valueOf(32);
		int t = scanner.nextInt();
		for(int i = 1; i <= t; i++) {
			a = scanner.nextBigDecimal();
			b = scanner.nextBigDecimal();
			if(a.compareTo(b) <= 0) {
				ans = a;
				a = b;
				b = ans;
			}
			a = a.subtract(b);
			if(a.compareTo(c) >= 0) ans = a.add(b);
			else {
				double tmp = Math.pow(2, a.doubleValue()) + 1;
				tmp = Math.log(tmp)/Math.log((double)2);
				ans = b.add(BigDecimal.valueOf(tmp));
			}
			ans = ans.setScale(9, BigDecimal.ROUND_HALF_UP);
			System.out.println("Case " + i + ": " + ans.toPlainString());
		}
	}
}


你可能感兴趣的:(JAVA大数)