6064번: 카잉 달력
https://www.acmicpc.net/problem/6064
# 코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int s = 0; s < T; s++) {
boolean check = false;
int m = sc.nextInt();
int n = sc.nextInt();
int x = sc.nextInt() - 1;
int y = sc.nextInt() - 1;
for (int i = x; i < (n * m); i += m) {
if (i % n == y) {
System.out.println(i + 1);
check = true;
break;
}
}
if (!check) {
System.out.println(-1);
}
}
}
}
'코딩테스트 > 자바 문제풀이' 카테고리의 다른 글
[CLASS 3: BFS] 백준 14940 쉬운 최단거리 (1) | 2024.11.20 |
---|---|
[CLASS 3: 최단경로] 백준 11403 경로 찾기 (0) | 2024.11.19 |
[CLASS 3: 문자열] 백준 5525 IOIOI (0) | 2024.11.17 |
[CLASS 3: BFS] 백준 2667 단지번호붙이기 (0) | 2024.11.16 |
[CLASS 3: BFS] 백준 2178 미로 탐색 (0) | 2024.11.15 |