code w/multiply of O(n)