# Number of terms in Geometric Series with given conditions

A geometric progression is a sequence of integers b1, b2, b3, …, where for each i > 1, the respective term satisfies the condition bi = bi-1 * q, where q is called the common ratio of the progression.

Given geometric progression b defined by two integers b1 and q, and m “bad” integers a1, a2, .., am, and an integer l, write all progression terms one by one (including repetitive) while condition |bi| <= l is satisfied (|x| means absolute value of x).

Calculate how many numbers will be there in our sequence, or print “inf” in case of infinitely many integers.
Note: If a term equals one of the “bad” integers, skip it and move forward to the next term.

Examples:

Input : b1 = 3, q = 2, l = 30,
m = 4
6 14 25 48
Output : 3
The progression will be 3 12 24.
6 will also be there but because
it is a bad integer we won't include it

Input : b1 = 123, q = 1, l = 2143435
m = 4
123 11 -5453 141245
Output : 0
As value of q is 1, progression will
always be 123 and would become infinity
but because it is a bad integer we
won't include it and hence our value
will become 0

Input : b1 = 123, q = 1, l = 2143435
m = 4
5234 11 -5453 141245
Output : inf
In this case, value will be infinity
because series will always be 123 as
q is 1 and 123 is not a bad integer.

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach:
We can divide our solution in different cases:
Case 1: If starting value of series is greater than the given limit, output is 0.
Case 2: If starting value of series or q is 0, there are three more cases:
Case 2.a: If 0 is not given as a bad integer, answer will become inf.
Case 2.b: If b1 != 0 but q is 0 and b1 is also not a bad integer, answer will become 1.
Case 2.c: If 0 is given as a bad integer and b1 = 0, answer will become 0.
Case 3: If q = 1 we will check if b1 is given as a bad integer or not. If it is then answer will be 0 else answer will be inf.
Case 4: If q = -1, check if b1 and -b1 is present or not, if they are present our answer will be 0 else our answer will be inf.
Case 5: If none of the above cases hold, simply run a loop for b1 till l and calculate the number of elements.

Below is the implementation of above approach:

## C#

Output:

3

This article is contributed by Sarthak Kohli. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.