Fixed a wrong calculation for g(n) value