Primality Test | Set 5 ( Using Lucas | C # program to find out Lucas - Lehmer series . ; Function to find out first n terms ( considering4 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
using System ; using System . Collections . Generic ; class GFG { static void LucasLehmer ( int n ) { long current_val = 4 ; List < long > series = new List < long > ( ) ; series . Add ( current_val ) ; for ( int i = 0 ; i < n ; i ++ ) { current_val = current_val * current_val - 2 ; series . Add ( current_val ) ; } for ( int i = 0 ; i <= n ; i ++ ) Console . WriteLine ( " Term ▁ " + i + " : ▁ " + series [ i ] ) ; } static void Main ( ) { int n = 5 ; LucasLehmer ( n ) ; } }