I have the following series, infinitely long.
1 2 4 7 11 16 22 29 37.....
and I need to find a given number (say, N) whether it exists in this series or, not. The number again can be input any number of times and can be not-surprisingly, a long long value. Considering the series is infinite, I thought it irrelevant to create a data structure to store the elements(am I too dumb here?)
Took a closer look in this series, and i found that the difference between consecutive terms form an Arithmetic progression.
1 2 3 4 5 6 7 8.....
So, one easiest way would be keep on adding them starting from 1 and if we reach ==N, output Yes, else if >N, No. But this will be the costliest algorithm of what I can think of. I must be missing some very acute logic, but not sure.