http://www.reshebnik.ru/solutions/5/1
http://www.reshebnik.ru/solutions/5/4

я бы написала и так, и иначе