#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int P,Q,X,p,q,Y; p--,q--; while(X < Y){ p++,q++,X++; if(p == P) p = 0; if(q == Q) q = 0; } while(X > Y){ p--,q--,X--; if(p < 0) p += P; if(q < 0) q += Q; } cout << p+1 << " " << q+1 << endl; }