4fd800b3a8 2011-02-23 kinaba: #include <iostream> 4fd800b3a8 2011-02-23 kinaba: #include <vector> 4fd800b3a8 2011-02-23 kinaba: #include <cmath> 4fd800b3a8 2011-02-23 kinaba: #include <set> 4fd800b3a8 2011-02-23 kinaba: #include <algorithm> 4fd800b3a8 2011-02-23 kinaba: using namespace std; 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: struct AvoidingProduct 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: vector<int> getTriple(vector<int> a, int n) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: int best = 1000000000; 4fd800b3a8 2011-02-23 kinaba: vector<int> ans(3); 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: set<int> as(a.begin(), a.end()); 4fd800b3a8 2011-02-23 kinaba: for(int x=1;; ++x) if( !as.count(x) ) { 4fd800b3a8 2011-02-23 kinaba: for(int y=x;; ++y) if( !as.count(y) ) { 4fd800b3a8 2011-02-23 kinaba: for(int z=y;; ++z) if( !as.count(z) ) { 4fd800b3a8 2011-02-23 kinaba: int m = x*y*z; 4fd800b3a8 2011-02-23 kinaba: if( abs(m-n) < best ) { 4fd800b3a8 2011-02-23 kinaba: best = abs(m-n); 4fd800b3a8 2011-02-23 kinaba: ans[0] = x; 4fd800b3a8 2011-02-23 kinaba: ans[1] = y; 4fd800b3a8 2011-02-23 kinaba: ans[2] = z; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: if( x*y*z>n ) break; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: if( x*y*y>n ) break; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: if( x*x*x>n ) break; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: return ans; 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: };