The same question was asked almost 7 years ago. It turned out to be a matter of terminology in different textbooks between the terms "path" and "walk". While the answers addressed the OP's question, who meant to say "walk" instead, I am hoping for an answer for (actual) paths, that has no repeating vertex/edge visits.
Let's say I always reset the diagonal to zero after each power $A^k = A^{k-1} A$, $ \text{Diag}(A^k) := 0 $ to ban repeated visits to the same vertices. How to go about reasoning mathematically the correctness of this approach? Or if a more "proper" solution exists other than this hack?
I am aware that, if we are looking instead for $k$-lengthed shortest path, the first time an entry $a^k_{i,j}$ switches from 0 to >0 gives the number of shortest paths of length $k$ between two vertices $i$ and $j$. Because it is "too short" for loops to have occurred. But this isn't the total number of $k$-lengthed paths, which includes less efficient loopless paths as well.