Skip to content

Instantly share code, notes, and snippets.

@wfwei
Created March 25, 2013 14:44
Show Gist options
  • Select an option

  • Save wfwei/5237595 to your computer and use it in GitHub Desktop.

Select an option

Save wfwei/5237595 to your computer and use it in GitHub Desktop.
Fib...
package mine.old.staff;
public class Fib {
static final int MAX = 93;
static long[] f = new long[MAX];
static {
f[0] = 0;
f[2] = f[1] = 1;
}
public static long fib(int n) {
if (n < 3)
return f[n];
for (int i = 3; i <= n; i++)
f[i] = f[i - 1] + f[i - 2];
return f[n];
}
public static void main(String args[]) {
for (int i = 1; i < MAX; i++) {
System.out.println(fib(i));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment