[백준] 4948번 : 베르트랑 공준 - Java(자바)

강재원·2022년 10월 21일
0

[코딩테스트] Java

목록 보기
139/200



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

import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner s=new Scanner(System.in);
        while(true){
            int n=s.nextInt();
            if(n==0) break;
            int count=0;
            int cnt=0;
            for(int i=n+1;i<=2*n;i++){
                for(int j=2;j<=Math.sqrt(i);j++){
                    if(i%j==0){
                        cnt=1;
                        break;
                    }
                }
                if(cnt==0) count++;
                cnt=0;
            }
            System.out.println(count);
        }
    }
}
profile
개념정리 & 문법 정리 & 알고리즘 공부

0개의 댓글