Part of 2012 Canadian Mathematical Olympiad Qualification Repechage
Source: Canadian RepĂȘchage 2012: Problem 2