Code appears to work

-changed range to sqrt(n) instead of n/2