TopCoder – Single Round March 537

Here is my Div1-250 solution.

#define FOR(i,a,b)  for(int i=(a),_##i=(b);i<_##i;++i)
#define F(i,a)      FOR(i,0,a)
#define ALL(x)      x.begin(),x.end()
#define PB          push_back
#define MP          make_pair
#define S           size()
typedef long long   LL;

bool oki(int A, int x, int y){
   F(i, 201){
      if(A - (x*i) >= 0)
      if((A - (x*i)) % y == 0) return true;
      if(A - (y*i) >= 0)
      if((A - (y*i)) % x == 0) return true;
   }
   return false;
}

class KingXNewCurrency {
public:
   int howMany(int A, int B, int X) {
      int t = 0;
      FOR(y, 1, 206)
         if(oki(A, X, y) && oki(B, X, y))
            t++;
      if(t == 205) return -1;
      return t;
   }
}