@pradeep, first design the r.e. for na(w) mod 5 = 0. Then if you allow one extra 'a' either in the front or the back (doesnt matter), then the r.e. will get adjusted to na(w)mod 5 = 1. So you can write the r.e. for mod 5 > 0 i.e. mod 5 = 1, mod 5 = 2... mod 5 = 4 ;and finally add them up, and you'll land up with the same r.e. i've written.