rendered paste bodyimport java.math.BigInteger;
class Fibonacci {
public static void fibonacci (BigInteger i) {
BigInteger n0 = new BigInteger("0");
BigInteger n1 = new BigInteger("1");
BigInteger n = new BigInteger("1");
BigInteger nn = new BigInteger("0");
long t0 = System.currentTimeMillis();
long t1 = System.currentTimeMillis();
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());
t1 = System.currentTimeMillis();
}
n0 = n1;
n1 = nn;
n = n.add(new BigInteger("1"));
}
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]));
}
}