diff --git a/04- April/27- Bulb Switcher/27- Bulb Switcher (Noura Algohary).cpp b/04- April/27- Bulb Switcher/27- Bulb Switcher (Noura Algohary).cpp new file mode 100644 index 000000000..961cb34c3 --- /dev/null +++ b/04- April/27- Bulb Switcher/27- Bulb Switcher (Noura Algohary).cpp @@ -0,0 +1,12 @@ +// Author: Noura Algohary + +class Solution { +public: + int bulbSwitch(int n) { + // bulbs are counted (turned on) when it have odd number of divisors + // only numbers with perfect square roots have odd divisors + // to count the number of perfect square roots in n, + // it must be equal to sqrt(n) + return sqrt(n); + } +}; \ No newline at end of file diff --git a/04- April/27- Bulb Switcher/27- Bulb Switcher (Noura Algohary).py b/04- April/27- Bulb Switcher/27- Bulb Switcher (Noura Algohary).py new file mode 100644 index 000000000..effb9854e --- /dev/null +++ b/04- April/27- Bulb Switcher/27- Bulb Switcher (Noura Algohary).py @@ -0,0 +1,11 @@ +# Author: Noura Algohary + +class Solution: + def bulbSwitch(self, n: int) -> int: + # bulbs are counted (turned on) when it have odd number of divisors + # only numbers with perfect square roots have odd divisors + # to count the number of perfect square roots in n, + # it must be equal to sqrt(n) + + return int(n ** 0.5) + \ No newline at end of file