diff --git a/cpp/2305/LC230502CN.cpp b/cpp/2305/LC230502CN.cpp new file mode 100644 index 0000000..380d315 --- /dev/null +++ b/cpp/2305/LC230502CN.cpp @@ -0,0 +1,25 @@ +#include +#include + +class LC230502CN { +public: + static std::vector powerfulIntegers(int, int, int) noexcept; +}; + +std::vector LC230502CN::powerfulIntegers(int x, int y, int bound) noexcept { + if (bound < 2) + return {}; + if (x < y) + std::swap(x, y); + if (x <= 1) + return {2}; + std::unordered_set s { 2 }; + for (int ix = 1; ix + 1 <= bound; ix *= x) { + s.insert(ix + 1); + if (y <= 1) + continue; + for (int iy = 1; ix + iy <= bound; iy *= y) + s.insert(ix + iy); + } + return {s.begin(), s.end()}; +} diff --git a/cpp/2305/defs.h b/cpp/2305/defs.h index 552242c..fa34b8b 100644 --- a/cpp/2305/defs.h +++ b/cpp/2305/defs.h @@ -14,4 +14,10 @@ public: static double average(const std::vector&) noexcept; }; +class LC230502CN { +public: + static std::vector powerfulIntegers(int, int, int) noexcept; +}; + + #endif //LEETCODE_CPP_DEFS_H diff --git a/cpp/2305/main.cpp b/cpp/2305/main.cpp index a18352f..53e8086 100644 --- a/cpp/2305/main.cpp +++ b/cpp/2305/main.cpp @@ -1,9 +1,19 @@ #include +#include +#include #include "defs.h" +template +std::ostream& operator<<(std::ostream& os, const std::vector& x) noexcept { + for (auto&& i : x) + os << i << ", "; + return os; +} + int main() { std::cout << LC230501::average({1, 2, 3, 4}) << std::endl; std::cout << LC230501CN::numOfMinutes(1, 0, {-1}, {0}) << std::endl; + std::cout << LC230502CN::powerfulIntegers(2, 1, 10) << std::endl; return 0; }