-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboj_6064.java
More file actions
40 lines (35 loc) · 1.06 KB
/
boj_6064.java
File metadata and controls
40 lines (35 loc) · 1.06 KB
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
39
40
package brute_force;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class boj_6064 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T=Integer.parseInt(br.readLine());
StringTokenizer st;
for(int i=0;i<T;i++){
st=new StringTokenizer(br.readLine());
int M=Integer.parseInt(st.nextToken());
int N=Integer.parseInt(st.nextToken());
int x=Integer.parseInt(st.nextToken());
int y=Integer.parseInt(st.nextToken());
solve(x,y,M,N);
}
}
private static void solve(int x,int y, int M,int N){
boolean flag=false;
x--;
y--;
for(int j=x;j<=M*N;j+=M){
if(j%N==y){
flag=true;
System.out.println(j+1);
break;
}
}
if(!flag){
System.out.println("-1");
}
}
}