• 문제 링크
1773번: 폭죽쇼
2 1 2 1 1 1 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 위의 그림에서 1,2가 쓰여있는 4, 6, 8, 12, 16, 18, 20초에 폭죽이 밤 하늘에 터진다. 단 12초에는 두 폭죽이 동시에 하늘에 터지지만 한
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(), c = read(), p;
boolean[] arr = new boolean[c + 1];
while (n-- > 0) for (int i = p = read(); i <= c; i += p) arr[i] = true;
int cnt = 0;
for (boolean b : arr) if (b) cnt++;
bw.write(String.valueOf(cnt));
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' 카테고리의 다른 글
[백준] 2399 거리의 합 - Brute Force / Java (0) | 2023.12.28 |
---|---|
[백준] 13410 거꾸로 구구단 - Brute Force / Java (0) | 2023.12.27 |
[백준] 1233 주사위 - Brute Force / Java (0) | 2023.12.25 |
[백준] 14697 방 배정하기 - Brute Force / Java (0) | 2023.12.24 |
[백준] 30019 강의실 예약 시스템 - Greedy / Java (0) | 2023.12.23 |
댓글