-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDFT.cpp
35 lines (35 loc) · 945 Bytes
/
DFT.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
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <map>
using namespace std;
void gen(map<long long int, bool>& duplicates, vector<long long int>& vals,long long int val) {
duplicates[val] = true;
vals.push_back(val);
if(2*val <= 2147483648L && duplicates[2*val] == false) {
gen(duplicates, vals, 2*val);
}
if(3*val <= 2147483648L && duplicates[3*val] == false) {
gen(duplicates, vals, 3*val);
}
}
int main() {
vector<long long int> vals;
map<long long int, bool> duplicates;
gen(duplicates, vals, 1);
sort(vals.begin(), vals.end());
while(true) {
int M;
cin >> M;
if(M==0)
break;
if(binary_search(vals.begin(), vals.end(), M))
cout << M << endl;
else {
auto it = upper_bound(vals.begin(), vals.end(), M);
cout << *it << endl;
}
}
return 0;
}