Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- math
- 코테
- db
- 문자열
- 자바
- 건강
- DP
- 시뮬레이션
- 운동기록
- 코딩테스트
- greedy
- 러닝일지
- oracle
- binary search
- 백준
- 문제해결
- BOJ
- 알고리즘
- dfs
- MySQL
- Java
- BFS
- 투포인터
- priorityqueue
- 이분탐색
- SQL
- SWEA
- COS PRO
- 문제풀이
- 프로그래머스
Archives
- Today
- Total
슈콩
[BOJ] 백준 6064 카잉 달력 본문
[문제]
https://www.acmicpc.net/problem/6064
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int t = Integer.parseInt(br.readLine());
point:
while(t-->0) {
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());
if(m==x) x=0;
if(n==y) y=0;
int lcm = LCM(m,n);
for(int i=x;i<=lcm;i+=m) {
if(i==0) continue;
if(i%m==x && i%n==y) {
System.out.println(i);
continue point;
}
}
System.out.println(-1);
}
}
private static int LCM(int m,int n) {
return m / GCD(m,n) * n;
}
private static int GCD(int m,int n) {
if(n==0) return m;
return GCD(n,m%n);
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 1011 Fly me to the Alpha Centauri (0) | 2025.09.06 |
|---|---|
| [BOJ] 백준 11051 이항계수2 (0) | 2025.09.05 |
| [BOJ] 백준 11653 소인수분해 (0) | 2025.09.05 |
| [BOJ] 백준 8980 택배 (0) | 2025.09.05 |
| [BOJ] 백준 7570 줄 세우기 (0) | 2025.09.04 |