From c176d3e9a12f3196f9ecc7ea2ca909f078986dbd Mon Sep 17 00:00:00 2001 From: schlumphi Date: Sun, 8 Feb 2026 13:11:59 +0100 Subject: [PATCH 1/2] feat: nwd computation --- homework/nwd-nnw/nwdNww.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/homework/nwd-nnw/nwdNww.hpp b/homework/nwd-nnw/nwdNww.hpp index 0491a2c9..c6432281 100644 --- a/homework/nwd-nnw/nwdNww.hpp +++ b/homework/nwd-nnw/nwdNww.hpp @@ -1,8 +1,15 @@ #pragma once int NWD(int lhs, int rhs) { - // TODO: Implement me :) - return -1; + auto a = abs(lhs); + auto b = abs(rhs); + while (b != 0) { + auto c{a % b}; + a = b; + b = c; + } + + return a; } int NWW(int lhs, int rhs) { From 357327419e5d364f4d2782403e336615978589a7 Mon Sep 17 00:00:00 2001 From: schlumphi Date: Sun, 8 Feb 2026 13:16:37 +0100 Subject: [PATCH 2/2] feat: nww task done --- homework/nwd-nnw/nwdNww.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/homework/nwd-nnw/nwdNww.hpp b/homework/nwd-nnw/nwdNww.hpp index c6432281..3c8df69a 100644 --- a/homework/nwd-nnw/nwdNww.hpp +++ b/homework/nwd-nnw/nwdNww.hpp @@ -13,6 +13,9 @@ int NWD(int lhs, int rhs) { } int NWW(int lhs, int rhs) { - // TODO: Implement me :) - return -1; + if (lhs == 0 || rhs == 0) { + return 0; + } + + return abs(lhs) * abs(rhs) / NWD(lhs, rhs); }