Java代码。还没学java。淡淡的忧伤,碰到大数什么的就亏大了。当做模板照着先敲下来。http://blog.csdn.net/houserabbit/article/details/38397831
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static BigInteger two=BigInteger.valueOf(2);
public static BigInteger four=BigInteger.valueOf(4);
public static BigInteger six=BigInteger.valueOf(6);
public static HashMap<BigInteger,BigInteger> map=new HashMap<BigInteger,BigInteger>();
public static BigInteger F(BigInteger n)
{
if (map.containsKey(n))
return map.get(n);
BigInteger t1=n.divide(two);
BigInteger t2=n.mod(two);
BigInteger t3=t1.subtract(BigInteger.ONE);
if (t2.compareTo(BigInteger.ONE)==0)
t1=F(t1).multiply(four).add(t1.multiply(six));
else
t1=F(t1).multiply(two).add(F(t3).multiply(two)).add(t1.multiply(four)).subtract(four);
map.put(n, t1);
return t1;
}
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
map.put(BigInteger.ZERO, BigInteger.ZERO);
map.put(BigInteger.ONE, BigInteger.ZERO);
while (cin.hasNext())
{
BigInteger n=cin.nextBigInteger();
System.out.println(F(n));
}
cin.close();
}
}