diff --git a/homework/nwd-nnw/nwdNww.hpp b/homework/nwd-nnw/nwdNww.hpp index 0491a2c9..3c8df69a 100644 --- a/homework/nwd-nnw/nwdNww.hpp +++ b/homework/nwd-nnw/nwdNww.hpp @@ -1,11 +1,21 @@ #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) { - // TODO: Implement me :) - return -1; + if (lhs == 0 || rhs == 0) { + return 0; + } + + return abs(lhs) * abs(rhs) / NWD(lhs, rhs); }