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-backed certification.

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

P-NP Problem

Back to problem

Editorial

Rearranging P=N×PP=N\times PP=N×P gives (N−1)P=0(N-1)P=0(N−1)P=0. Thus the equality holds exactly when N=1N=1N=1 or P=0P=0P=0.

The main solution checks these two conditions. The naive solution directly computes N×PN\times PN×P and compares it with PPP. Both take O(1)O(1)O(1) time and extra space per case and O(T)O(T)O(T) total time. Both methods work under the full constraints.

Since ∣NP∣≤106|NP|\leq 10^6∣NP∣≤106 and ∣(N−1)P∣≤1 001 000|(N-1)P|\leq 1\,001\,000∣(N−1)P∣≤1, even signed 32-bit arithmetic is sufficient. Do not divide both sides by without checking it, since may be zero.

Solution written by GPT

001
000
PPP
PPP