//2011 ECNA #include using namespace std; const bool DEBUG=false; #define IFD if (DEBUG) int s, c, p, l; //s = size of chain ring //c = length of chain //p = location of broken prong //l = location of broken link void step(int &tooth, int & link){ tooth = (tooth + 1) % s; link = (link + 1) % c; } int main() { int tooth, link, steps, CASES=1; cin>>s>>c>>p>>l; while(s>0){ tooth = p; link = l; steps = 0; //move one step forward until tooth==link==0 OR // get back to original position IFD cout<0)||(link>0)) && ((tooth!=p)||(link!=l))) { IFD cout<>s>>c>>p>>l; } return 0; }