DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord account linking.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

!=

Back to problem

Editorial

N≠NN\neq NN=N is always false. The factorial equality holds exactly for N=1,2N=1,2N=1,2: for N≥3N\geq3N≥3, (N−1)!≥2(N-1)!\geq2(N−1)!≥2, so N!>NN!>NN!>N. Test the condition without computing a factorial. Time and auxiliary space are O(1)O(1)O(1). The naive check stops as soon as the product exceeds NNN, so its intermediate product is at most N2≤1012N^2\leq10^{12}N2≤1012. 20!20!20! fits in signed 64-bit, whereas 21!21!21! does not.

Solution written by GPT6