## 【HDU-5973】Game of Taking Stones【威佐夫博弈】

【HDU-5973】Game of Taking Stones【威佐夫博弈】

Solution:

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

public class Main {
private static final BigDecimal EPS = new BigDecimal("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001");
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
BigDecimal sqrt5 = sqrtNewtownMethod("5");
while (in.hasNext()) {
BigDecimal a = in.nextBigDecimal();
BigDecimal b = in.nextBigDecimal();
if (a.compareTo(b) > 0) {
BigDecimal t = a;
a = b;
b = t;
}
BigDecimal c = b.subtract(a).multiply(goldNum);
if (c.setScale(0, BigDecimal.ROUND_FLOOR).compareTo(a) == 0)
System.out.println("0");
else
System.out.println("1");
}
}
private static BigDecimal sqrtNewtownMethod(String b) {
BigDecimal two = BigDecimal.valueOf(2);
BigDecimal num = new BigDecimal(b);
BigDecimal pre = new BigDecimal(b);
BigDecimal crt = new BigDecimal("0");
while (true) {
// System.out.println(pre.subtract(pre.multiply(pre).subtract(num).divide(two.multiply(pre))));
crt = pre.subtract(pre.multiply(pre).subtract(num).divide(two.multiply(pre), 102, BigDecimal.ROUND_FLOOR));
if (crt.subtract(pre).abs().compareTo(EPS) < 0) break;
pre = crt;
}
return crt;
}
}