ex2 improve by vectorization
ex3