2006 AIME I Problem 13

For each even positive integer x, let g(x) denote the greatest power of 2 that divides x. For example, g(20)=4 and g(16)=16. For each positive integer n, let S_{n}=\sum_{k=1}^{2^{n-1}} g(2 k). Find the greatest integer n less than 1000 such that S_{n} is a perfect square.