user
Optimize the given code for performance.

Additional Context:
s = 0
for i in range(1,n):
     for j in range(1,i*i):
         if j % i == 0:
              s += j

Answer:
assistant
s = 0
i_sq = 1
for i in range(1,n):
     for j in range(i_sq,i*i+1):
         if j % i == 0:
              s += j
     i_sq = i*i+1 # The inner loop starts at the square of i