슈콩

[BOJ] 백준 6359 만취한 상범 본문

Algorithms/Baekjoon

[BOJ] 백준 6359 만취한 상범

shukong 2025. 9. 15. 23:22

[문제]

https://www.acmicpc.net/problem/6359

 

 

[소스 코드]

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));
		int t = Integer.parseInt(br.readLine());
		while(t-->0) {
			int n = Integer.parseInt(br.readLine());
			boolean[] open = new boolean[n+1];
			Arrays.fill(open, true);
			for(int i=2;i<=n;i++) {
				for(int j=i;j<=n;j+=i) {
					open[j] = !open[j];
				}
			}
			int result = 0;
			for(int i=1;i<=n;i++) {
				if(open[i])
					result++;
			}
			System.out.println(result);
		}
	}
}

'Algorithms > Baekjoon' 카테고리의 다른 글

[BOJ] 백준 9613 GCD 합  (0) 2025.09.16
[BOJ] 백준 9020 골드바흐의 추측  (0) 2025.09.15
[BOJ] 백준 5347 LCM  (0) 2025.09.15
[BOJ] 백준 3343 장미  (0) 2025.09.15
[BOJ] 백준 3343 캠핑  (0) 2025.09.15