File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed
Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change 11const SQ5 = 5 ** 0.5
2- //Square root of 5
2+ // Square root of 5
33
44const PHI = ( 1 + SQ5 ) / 2
55// definition of PHI
66
7- //theoretically it should take O(1) constant amount of time as long
7+ // theoretically it should take O(1) constant amount of time as long
88// arithmetic calculations are considered to be in constant amount of time
9- function EvenFibonacci ( limit ) {
9+ function EvenFibonacci ( limit ) {
1010 const highestIndex = Math . floor ( Math . log ( limit * SQ5 ) / Math . log ( PHI ) )
1111 const n = Math . floor ( highestIndex / 3 )
1212 return ( ( PHI ** ( 3 * n + 3 ) - 1 ) / ( PHI ** 3 - 1 ) -
1313 ( ( 1 - PHI ) ** ( 3 * n + 3 ) - 1 ) / ( ( 1 - PHI ) ** 3 - 1 ) ) / SQ5
1414}
15-
16- console . log ( EvenFibonacci ( 4e6 ) ) ;
15+ console . log ( EvenFibonacci ( 4e6 ) )
1716// Sum of Even Fibonnaci upto 4 Million
You can’t perform that action at this time.
0 commit comments