Sum of numbers from 1 to N which are in Lucas Sequence | C ++ program to find 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int LucasSum ( int N ) { int sum = 0 ; int a = 2 , b = 1 , c ; sum += a ; while ( b <= N ) { sum += b ; int c = a + b ; a = b ; b = c ; } return sum ; } int main ( ) { int N = 20 ; cout << LucasSum ( N ) ; return 0 ; }