don't check k <= n twice