Optimized to check till root-n only