text: Primality Test | Set 5 ( Using Lucas | Function to find out first n terms ( considering 4 as 0 th term ) of Lucas - Lehmer series . ; the 0 th term of the series is 4. ; create an array to store the terms . ; compute each term and add it to the array . ; print out the terms one by one . ; Driver Code
code: function LucasLehmer ( n ) { let current_val = 4 ; let series = [ ] ; series . push ( current_val ) ; for ( let i = 0 ; i < n ; i ++ ) { current_val = ( current_val * current_val ) - 2 ; series . push ( current_val ) ; } for ( let i = 0 ; i <= n ; i ++ ) { document . write ( " " + i + " " + series [ i ] + " " ) ; } } let n = 5 ; LucasLehmer ( n ) ;