import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
/**
* Created by dezhonger on 2017/12/18
*/
public class PE169 {
static Map<String, BigInteger> map = new HashMap<>();
static BigInteger two = new BigInteger("2");
public static BigInteger f(BigInteger n) {
if (1 == n.intValue()) return BigInteger.ONE;
if (0 == n.intValue()) return BigInteger.ONE;
if (map.get(n.toString()) != null) return map.get(n.toString());
BigInteger result = null;
if (1 == n.mod(two).intValue()) {
result = f(n.divide(two));
} else {
result = f(n.divide(two).subtract(BigInteger.ONE)).add(f(n.divide(two)));
}
map.put(n.toString(), result);
return result;
}
public static void main(String[] args) {
String s2 = "10000000000000000000000000";
System.out.println(f(new BigInteger(s2)));
}
}
PE169
最新推荐文章于 2022-11-01 10:08:39 发布