• 문제 링크
18265번: MooBuzz
Farmer John's cows have recently become fans of playing a simple number game called "FizzBuzz". The rules of the game are simple: standing in a circle, the cows sequentially count upward from one, each cow saying a single number when it is her turn. If a c
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read();
long low = n, high = n * 2L;
while (low <= high) {
long mid = (low + high) / 2;
if (n > mid - (mid / 3 + mid / 5 - mid / 15)) low = mid + 1;
else high = mid - 1;
}
bw.write(String.valueOf(low));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 17124 두 개의 배열 - BinarySearch / Java (0) | 2023.08.11 |
---|---|
[백준] 13702 이상한 술집 - BinarySearch / Java (0) | 2023.08.10 |
[백준] 1072 게임 - BinarySearch / Java (0) | 2023.08.08 |
[백준] 15092 Sheba’s Amoebas - Graph Theory / Java (0) | 2023.08.07 |
[백준] 14397 해변 - Graph Theory / Java (0) | 2023.08.06 |
댓글