We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f88c647 + a0482a7 commit 66c800aCopy full SHA for 66c800a
lectures/15-complexity/code/src/com/kunal/Fibo.java
@@ -9,9 +9,9 @@ public static void main(String[] args) {
9
System.out.println(fiboFormula(50));
10
}
11
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));
+ static int fiboFormula(int n){
+ // just for demo, use long instead
+ return (int) ((Math.pow(((1+Math.sqrt(5))/2),n)-Math.pow(((1-Math.sqrt(5))/2),n))/Math.sqrt(5));
15
16
17
static int fibo(int n) {
@@ -21,4 +21,4 @@ static int fibo(int n) {
21
22
return fibo(n-1) + fibo(n-2);
23
24
-}
+}
0 commit comments