Part of 2005 Mediterranean Mathematics Olympiad
Source: Mediterranian Mathematics Competition 2005, Problem 3