-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
38 lines (36 loc) · 888 Bytes
/
Main.java
File metadata and controls
38 lines (36 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package bishi;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int result[]=new int[n];
for(int i=0;i<n;i++){
int N=sc.nextInt();
int M=sc.nextInt();
if(N==0||M==0){
result[i]=0;
continue;
}
result[i]=getNum(N,M);
}
for(int res:result){
System.out.println(res);
}
}
public static int getNum(int row,int col){
int result=0;
if(row>=2&&col>=2){
result=result+(row-2)*(col-2);
}
if(row==1&&col>=2){
result=col-2;
}
if(col==1&&row>=2){
result=row-2;
}
if(col==1&&row==1)
result=1;
return result;
}
}