#include using namespace std; #include using namespace atcoder; using ll = long long; ll h,w,d,sx,sy,tx,ty,vx,vy; void solve(){ ll xyv[16][16][2][2]; //tx--,ty--,sx--,sy--; for(ll i = 0;i<16;i++){ for(ll j = 0;j<16;j++){ for(ll k = 0;k<2;k++){ for(ll l = 0;l<2;l++){ xyv[i][j][k][l] = -1; } } } } { ll g = gcd(vx,vy); vx/=g; vy/=g; d *= g; } ll x = sx,y = sy; ll loop = INT_MAX/2; for(ll i = 0;iw){ sx = w-1; vx = -vx; } } } for(ll j = 0;jh){ sy = h-1; vy = -vy; } } } if(xyv[sx][sy][vx>=0][vy>=0]>=0){ break; } xyv[sx][sy][vx>=0][vy>=0] = i; if(sx==tx&&sy==ty){ cout<<"Hit"<> t; while(t--){ cin >> w >> h >> d >> sx >> sy >> tx >> ty >> vx >> vy; swap(sx,tx); swap(sy,ty); solve(); } }