From 826b402dd10b97101caaf2cfdcc478c0d113a77c Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Thu, 4 Aug 2022 21:35:42 +0200 Subject: [PATCH] problems: add mirror reflection Signed-off-by: Matej Focko --- problems/mirror-reflection.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 problems/mirror-reflection.cpp diff --git a/problems/mirror-reflection.cpp b/problems/mirror-reflection.cpp new file mode 100644 index 0000000..2cc82ea --- /dev/null +++ b/problems/mirror-reflection.cpp @@ -0,0 +1,18 @@ +class Solution { +public: + int mirrorReflection(int p, int q) + { + auto lcm = p * q / std::gcd(p, q); + auto x = lcm / p; + auto y = lcm / q; + + if (x % 2 == 0) { + return 0; + } + + if (y % 2 == 0) { + return 2; + } + return 1; + } +};