Divisible Subarrays TLE problem

The second test case is showing TLE. Couldn’t fix it. Please point out how can I optimize it.
Here is my code.