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.
1 parent b423cf2 commit 006df2dCopy full SHA for 006df2d
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 long 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