Skip to content

Commit 006df2d

Browse files
Update Fibo.java
1 parent b423cf2 commit 006df2d

File tree

1 file changed

+4
-4
lines changed
  • lectures/15-complexity/code/src/com/kunal

1 file changed

+4
-4
lines changed

lectures/15-complexity/code/src/com/kunal/Fibo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public static void main(String[] args) {
99
System.out.println(fiboFormula(50));
1010
}
1111

12-
static int fiboFormula(int n) {
13-
// just for demo, use long instead
14-
return (int)(Math.pow(((1 + Math.sqrt(5)) / 2), n) / Math.sqrt(5));
12+
static long fiboFormula(int n){
13+
// just for demo, use long instead
14+
return (int) ((Math.pow(((1+Math.sqrt(5))/2),n)-Math.pow(((1-Math.sqrt(5))/2),n))/Math.sqrt(5));
1515
}
1616

1717
static int fibo(int n) {
@@ -21,4 +21,4 @@ static int fibo(int n) {
2121
}
2222
return fibo(n-1) + fibo(n-2);
2323
}
24-
}
24+
}

0 commit comments

Comments
 (0)