5cbddaf9a4 2017-05-20 kinaba: #include <iostream> 5cbddaf9a4 2017-05-20 kinaba: #include <sstream> 5cbddaf9a4 2017-05-20 kinaba: #include <iomanip> 5cbddaf9a4 2017-05-20 kinaba: #include <vector> 5cbddaf9a4 2017-05-20 kinaba: #include <string> 5cbddaf9a4 2017-05-20 kinaba: #include <map> 5cbddaf9a4 2017-05-20 kinaba: #include <set> 5cbddaf9a4 2017-05-20 kinaba: #include <algorithm> 5cbddaf9a4 2017-05-20 kinaba: #include <numeric> 5cbddaf9a4 2017-05-20 kinaba: #include <iterator> 5cbddaf9a4 2017-05-20 kinaba: #include <functional> 5cbddaf9a4 2017-05-20 kinaba: #include <complex> 5cbddaf9a4 2017-05-20 kinaba: #include <queue> 5cbddaf9a4 2017-05-20 kinaba: #include <stack> 5cbddaf9a4 2017-05-20 kinaba: #include <cmath> 5cbddaf9a4 2017-05-20 kinaba: #include <cassert> 5cbddaf9a4 2017-05-20 kinaba: #include <tuple> 5cbddaf9a4 2017-05-20 kinaba: using namespace std; 5cbddaf9a4 2017-05-20 kinaba: typedef long long LL; 5cbddaf9a4 2017-05-20 kinaba: typedef complex<double> CMP; 5cbddaf9a4 2017-05-20 kinaba: 5cbddaf9a4 2017-05-20 kinaba: int gcd(int a, int b) 5cbddaf9a4 2017-05-20 kinaba: { 5cbddaf9a4 2017-05-20 kinaba: while (a) 5cbddaf9a4 2017-05-20 kinaba: swap(a, b %= a); 5cbddaf9a4 2017-05-20 kinaba: return b; 5cbddaf9a4 2017-05-20 kinaba: } 5cbddaf9a4 2017-05-20 kinaba: 5cbddaf9a4 2017-05-20 kinaba: 5cbddaf9a4 2017-05-20 kinaba: class FoxAndCake2 { public: 5cbddaf9a4 2017-05-20 kinaba: string isPossible(int c, int s) 5cbddaf9a4 2017-05-20 kinaba: { 5cbddaf9a4 2017-05-20 kinaba: return solve(c, s) ? "Possible" : "Impossible"; 5cbddaf9a4 2017-05-20 kinaba: } 5cbddaf9a4 2017-05-20 kinaba: 5cbddaf9a4 2017-05-20 kinaba: bool solve(int a, int b) 5cbddaf9a4 2017-05-20 kinaba: { 5cbddaf9a4 2017-05-20 kinaba: if (gcd(a, b) != 1) 5cbddaf9a4 2017-05-20 kinaba: return true; 5cbddaf9a4 2017-05-20 kinaba: 5cbddaf9a4 2017-05-20 kinaba: for (int x = 2; x <= 100 && x < a; ++x) 5cbddaf9a4 2017-05-20 kinaba: for (int y = 2; y <= 100 && y < b; ++y) 5cbddaf9a4 2017-05-20 kinaba: if (gcd(x, y) != 1 && gcd(a - x, b - y) != 1) 5cbddaf9a4 2017-05-20 kinaba: return true; 5cbddaf9a4 2017-05-20 kinaba: return false; 5cbddaf9a4 2017-05-20 kinaba: } 5cbddaf9a4 2017-05-20 kinaba: }; 5cbddaf9a4 2017-05-20 kinaba: 5cbddaf9a4 2017-05-20 kinaba: // BEGIN CUT HERE 5cbddaf9a4 2017-05-20 kinaba: #include <ctime> 5cbddaf9a4 2017-05-20 kinaba: double start_time; string timer() 5cbddaf9a4 2017-05-20 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 5cbddaf9a4 2017-05-20 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 5cbddaf9a4 2017-05-20 kinaba: { os << "{ "; 5cbddaf9a4 2017-05-20 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 5cbddaf9a4 2017-05-20 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 5cbddaf9a4 2017-05-20 kinaba: void verify_case(const string& Expected, const string& Received) { 5cbddaf9a4 2017-05-20 kinaba: bool ok = (Expected == Received); 5cbddaf9a4 2017-05-20 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 5cbddaf9a4 2017-05-20 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 5cbddaf9a4 2017-05-20 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 5cbddaf9a4 2017-05-20 kinaba: #define END verify_case(_, FoxAndCake2().isPossible(c, s));} 5cbddaf9a4 2017-05-20 kinaba: int main(){ 5cbddaf9a4 2017-05-20 kinaba: 5cbddaf9a4 2017-05-20 kinaba: CASE(0) 5cbddaf9a4 2017-05-20 kinaba: int c = 74; 5cbddaf9a4 2017-05-20 kinaba: int s = 109; 5cbddaf9a4 2017-05-20 kinaba: string _ = "Possible"; 5cbddaf9a4 2017-05-20 kinaba: END 5cbddaf9a4 2017-05-20 kinaba: CASE(1) 5cbddaf9a4 2017-05-20 kinaba: int c = 1000000000; 5cbddaf9a4 2017-05-20 kinaba: int s = 1000000000; 5cbddaf9a4 2017-05-20 kinaba: string _ = "Possible"; 5cbddaf9a4 2017-05-20 kinaba: END 5cbddaf9a4 2017-05-20 kinaba: CASE(2) 5cbddaf9a4 2017-05-20 kinaba: int c = 1; 5cbddaf9a4 2017-05-20 kinaba: int s = 58; 5cbddaf9a4 2017-05-20 kinaba: string _ = "Impossible"; 5cbddaf9a4 2017-05-20 kinaba: END 5cbddaf9a4 2017-05-20 kinaba: CASE(3) 5cbddaf9a4 2017-05-20 kinaba: int c = 223092871; 5cbddaf9a4 2017-05-20 kinaba: int s = 446185741; 5cbddaf9a4 2017-05-20 kinaba: string _ = "Possible"; 5cbddaf9a4 2017-05-20 kinaba: END 5cbddaf9a4 2017-05-20 kinaba: /* 5cbddaf9a4 2017-05-20 kinaba: CASE(4) 5cbddaf9a4 2017-05-20 kinaba: int c = ; 5cbddaf9a4 2017-05-20 kinaba: int s = ; 5cbddaf9a4 2017-05-20 kinaba: string _ = ; 5cbddaf9a4 2017-05-20 kinaba: END 5cbddaf9a4 2017-05-20 kinaba: */ 5cbddaf9a4 2017-05-20 kinaba: } 5cbddaf9a4 2017-05-20 kinaba: // END CUT HERE