Образцы решений: http://reshebnik.ru/solutions/10/1/ и http://reshebnik.ru/solutions/10/8/