Sum of numbers from 1 to N which are in Lucas Sequence | Function to return the required sum ; Generate lucas number and keep on adding them ; Driver code
function LucasSum ( N ) { var sum = 0 ; var a = 2 , b = 1 , c ; sum += a ; while ( b <= N ) { sum += b ; var c = a + b ; a = b ; b = c ; } return sum ; } var N = 20 ; document . write ( LucasSum ( N ) ) ;