use a calculation instead of loop