This problem is in Contest(s) below:
Contest 1245:数论入门
Contest 1345:数论的题2