알고리즘 풀이/백준
[백준][Java] 1978번 소수 찾기
배게
2018. 4. 28. 19:46
728x90
소수의 조건에 일치하는, 즉 1과 자기자신으로만 나누어지는
수를 counting하여 마지막에 그 수를 출력해줍니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int input; int res=0; int mok, mok_0; for (int i=0; i<N; i++) { mok_0=0; input = sc.nextInt(); for(mok=1; mok<=input; mok++) { if(input%mok==0) mok_0++; } if(mok_0==2) res++; } System.out.println(res); } } |