simplify loop.go

In particular, replaced a loop that was doing modular arithmetic with its closed form.