From the solution you have provided I am assuming main memory access time 10 unit and cache access time is 1 unit.
While calculating execution time without cache we have total 500 instruction out of which 100 instruction runs in loops for 25 times and rest (500-100)=400 instruction runs once.
So ,total number of times we have to go to main memory to fetch the instruction as we don’t have cache to store the instructions is =(400+25*100)=2900.
Now each instruction it took 10 unit time to access main memory .
So total time required to run 2900 instruction=2900*10=29000 unit time
When we use cache we can store the looping instruction inside the cache so that we don’t have to go to fetch those 100 instruction every time.
So ,we have to definitely fetch those 500 instruction once from memory which will took 500*10=5000 unit time .
now by this we store the 100 instruction inside the cache and run them once .
now we need to run them only 24 times as we already run them once.
Now we can easily access them from cache which will take 1 unit of time to access one instruction.
So , to access 100 instruction once it will took =100*1=100 unit time.
we need to execute them 24 times so time it took =24*100=2400 unit time.
So total time it took without cache=5000+2400=7400 unit time.
Speed up=$\frac{29000}{7400}=3.91$