Little Cake and Chef June LoC

I have solved the problem by finding the product of all contiguous arrays and the finding out the prime factor of each number and checking First and second subcases are accepted third and fourth is TLE please help !

Question: link text
solution:link text

Instead of doing prime factorization of the product of sub-array every time,precompute the prime factors of every element and store them in an adjacency list .

Here is my accepted solution for reference:

https://www.codechef.com/viewsolution/14373822

It would be really helpful to follow your code if you could elaborate your logic a bit, Thank you .