Input: x = 3, y = 5, bound = 15 Output: [2,4,6,8,10,14]
Note:
1 <= x <= 100 1 <= y <= 100 0 <= bound <= 10^6
Solutions
straight forward
classSolution{public:vector<int>powerfulIntegers(intx,inty,intbound){ unordered_set<int> s;for(int a =1; a < bound; a *= x){for(int b =1; a + b <= bound; b *= y){s.insert(a + b);if(y ==1)break;}if(x ==1)break;}return{s.begin(),s.end()};}};