Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int M, N, n, t;
- int timee;
- int x, y, w, z;
- int is_valid = 0;
- cin >> n;
- for(t=0; t<n; t++){
- cin >> M >> N >> w >> z ;
- is_valid = 0;
- timee = 1;
- for(x=1, y=1; !((x == M) && (y == N));){
- if(x<M){
- x++;
- }else{
- x = 1;
- }
- if(y<N){
- y++;
- }else{
- y = 1;
- }
- timee++;
- if((x == w) && (y == z)){
- is_valid = 1;
- cout << timee << "\n";
- continue;
- }
- }
- if(is_valid == 0){
- cout << -1 << "\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement