Homework for session 5 plus session 3 and 4 stuff

could you do this without repeating an code? i.e the smae code for i%2, i%3, etc...