Is it a good practice to store the results of various test cases in a array then giving the output so that the output becomes fast…

The constraints being less which ensure that the results could be stored in a array

for eg

storing all the prime numbers in a array and then outputting the required number of prime numbers between 2 numbers