how do I do a formula to automatically put numbers in a cell

if a1 = 1

I would like a2, a3, a4, a5, a6..... to be 2,3,4,1,2,3,4.....

how do I make the sequence change from 4 back to 1

ie. a1 maybe 3

thus a2,a3,a4,a5,6......would be 4,1,2,3,4,12.......

what would the formulas be in the cells


andrewm