Given a set associative cache.

$l-Number\,of\,sets$

$b-\,block\,size$

$k *b - \, set\,size$

So given set associativity=k

**Number of sets in cache**=$l$

Size of loop=$n*b \rightarrow k*m*b$(Means $k*m$ number of blocks of Main memory)

Considering worst case when $m=l$

Size of loop(In blocks)=$l*k$

Now Mapping function of this cache=(MM Block Number) $mod\,l=(l*k)mod\,l$ means atmost "K" blocks can map into the same set.

**What is the set associativity of this cache=>K**(means at max, K blocks of Main-memory can be accommodated without replacement which maps into the same set).

So, this means, even in worst case, after my full loop comes into the cache, then subsequent accesses to the loop won't cause replacement in the cache and full loop can be accommodated in the cache without any replacement.

**At first iteration:** All "n" Main-memory blocks will be brought into the cache and mapped into "L" sets of cache having "K" lines each.

**So, first "n" misses here(In terms of blocks).**

For Remaining 99 iterations: Since, now full loop is in cache, so no cache misses.

-------------------------------------------------------------------------------------------------------------------------------

Or we can directly give the answer now. Only during the first iteration, misses will occur and the remaining 99 iterations will be a hit.

So, hit ratio=99 percent.

Hit rate=$\frac{100n-n}{100n}=0.99=99\,percent$