# AVNRSER - Editorial

Contest

Practice

Author: Mrinal Sinha

Editorialist: Mrinal Sinha

Tester: Amit Kumar Pandey

EASY

Math

### PROBLEM:

Starlord is stuck in space on his way back after a successful mission when his spacecraft crashed. He now has to go jumping from asteroid to asteroid to get to a nearby space camp. The asteroids are in such an order that their lengths increase to a certain extent as he jumps to the next asteroid. The series of the lengths of the asteroids is given below. For a given asteroid, you have to determine whether it comes in his path or not.
Series: 44, 120, 304, 736

### EXPLANATION:

The series given here is an Arithmetico-Geometrico Series with numbers written as 11 `*` 4, 15`*`8, 19`*`16 and 23`*`32 respectively. Thus the first term of the A.P is 11 with common difference 4 whereas the first term of G.P is 4 with common ratio 2. With the help of above values we can determine the previous positive values which will be 7`*`2 =14 and 3`*`1 = 3.

Thus the general formula for the above expression is (a+(n-1)`*`d)`*`(b`*`pow(r,n-1)), where ‘a’ is the 1st term of the A.P (which is 3), ‘d’ is the common difference of the A.P (which is 4), ‘b’ is the 1st term of G.P (which is 1), ‘r’ is the common ratio of the G.P (which is 2) and ‘n’ is the nth term of the series.

Thus initialize n with 1 and calculate the value of above expression.

Thus initialize n with 1 and calculate the value of above expression.

*If the value is equal to the given number, then print “YES”.

• If the value is greater than the given number ,then print “NO”.

*If the value is less than the given number, then increment n by 1 and again check whether the value of the expression is greater than or equal to the given number. Do this step until the 1st or 2nd step is satisfied.

### AUTHOR’S AND EDITORIALIST’S SOLUTIONS:

Author’s solution can be found here.

Editorialist’s solution can be found here.

Tester’s solution can be found here.

1 Like