Help me in solving COPR16G problem

My issue

what is problem in my solution so taht it is showing that time limit exceeded.

My code

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef {
   static int gcd(int a, int b){
        while (b != 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }


    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int no = input.nextInt();
        for (int i = 0; i < no; i++) {
            int a = input.nextInt();
            int b = input.nextInt();
            int c = Math.max(a, b);
            int d = Math.min(a, b);
            if (gcd(c, d) == 1) {
                System.out.println(c * d - c - d+1);
            } else {
                System.out.println(-1);
            }
        }
    }
}

Problem Link: Get AC in one go Practice Coding Problem