improve code for Ex_4_3, avoid integer overflow