rendered paste bodyimport java.math.BigInteger;
class Fibonacci {
public static void fibonacci (BigInteger i) {
BigInteger n0 = BigInteger.ZERO;
BigInteger n1 = BigInteger.ONE;
BigInteger n = BigInteger.ONE;
BigInteger nn = BigInteger.ZERO;
long t0 = System.currentTimeMillis();
long t1 = t0;
long t2;
while (i.compareTo(n) > 0) {
nn = n0.add(n1);
t2 = System.currentTimeMillis();
if ((t2 - t1) > 5000) {
System.out.println(n.toString() + " (" + nn.bitLength() + " bit) -- " +
Runtime.getRuntime().freeMemory() / 1024 + "k of " +
Runtime.getRuntime().totalMemory() / 1024 + "k");
t1 = System.currentTimeMillis();
}
n0 = n1;
n1 = nn;
n = n.add(BigInteger.ONE);
}
System.out.println(n.toString() + " (" + nn.bitLength() + " bit)");
System.out.println((System.currentTimeMillis() - t0) / 1000 + " seconds");
}
public static void main (String... args) {
fibonacci(new BigInteger(args[0]));
}
}