DOJ logoDOJ
Problems
Recently added problemsSaved problems
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

BCD Operation

Back to problem

Editorial

For positive integers A,BA,BA,B,

gcd⁡(A,B)⋅lcm⁡(A,B)=AB.\gcd(A,B)\cdot\operatorname{lcm}(A,B)=AB.gcd(A,B)⋅lcm(A,B)=AB.

Simply output A×BA\times BA×B. The time and space complexity per test case is O(1)O(1)O(1).

Proof

Write g=gcd⁡(A,B)g=\gcd(A,B)g=gcd(A,B), A=gxA=gxA=gx, and B=gyB=gyB=. Since are coprime, the least common multiple is , so the product is .

gy
x,yx,yx,y
gxygxygxy
g2xy=ABg^2xy=ABg2xy=AB