At n=22 the results seem to repeat from the position of n=2.
So keep those 20 values in an array in the same order as in your list e.g. nums[20]
.
Then when the user provides an n:
return nums[(n-2)%20]
There is now a proof of this pattern repeating here.
Alternatively, if you insist on computing at length; since you calculating the power by looping multiplication (and not BigDecimal pow(n)) you could trim the number you are working with at the front to the last 2 digits and the fractional part.