Sylvester 's sequence | Javascript program to print terms of Sylvester 's sequence ; To store the product . ; To store the current number . ; Loop till n . ; Driver Code
let N = 1000000007 ; function printSequence ( n ) { let a = 1 ; let ans = 2 ; for ( let i = 1 ; i <= n ; i ++ ) { document . write ( ans + " " ) ; ans = ( ( a % N ) * ( ans % N ) ) % N ; a = ans ; ans = ( ans + 1 ) % N ; } } let n = 6 ; printSequence ( n ) ;