Part of 2009 Canadian Mathematical Olympiad Qualification Repechage
Source: Canadian RepĂȘchage 2009: Problem 8