백준 #6359번 만취한 상범

jhj·2025년 1월 18일

백준 JAVA

목록 보기
559/583
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 i = 0; i < t; i++) {
			int a = sc.nextInt();
			int[] b = new int[a + 1];
			for(int j = 0; j < b.length; j++) {
				b[j] = -1;
			}
			
			for(int j = 1; j < b.length; j++) {
				for(int k = j; k < b.length; k++) {
					if(k % j == 0) {
						if(b[k] == -1) {
							b[k] = 1;
						}else if(b[k] == 1) {
							b[k] = -1;
						}
					}
				}
			}
			
			int count = 0;
			for(int j = 0; j < b.length; j++) {
				if(b[j] == 1) {
					count++;
				}
			}
			System.out.println(count);
		}
		sc.close();
	}
}
profile
개발자를 꿈꾸는

0개의 댓글