Fafa and Ancient Mathematics

CodeForces - 935E