forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
40 lines (32 loc) · 839 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/// Source : https://leetcode.com/problems/powerful-integers/
/// Author : liuyubobobo
/// Time : 2019-01-05
#include <iostream>
#include <unordered_set>
#include <vector>
#include <cmath>
using namespace std;
/// Brute Force
/// Time Complexity: O(log(bound)^2)
/// Space Complexity: O(n)
class Solution {
public:
vector<int> powerfulIntegers(int x, int y, int bound) {
unordered_set<int> res;
for(int i = 0;;i ++){
int powx = pow(x, i);
if(powx > bound) break;
for(int j = 0;;j ++) {
int t = powx + pow(y, j);
if(t > bound) break;
res.insert(t);
if(y == 1) break;
}
if(x == 1) break;
}
return vector<int>(res.begin(), res.end());
}
};
int main() {
return 0;
}