This solution is wrong, works for small n but for large n computation time > 1s :P