반응형
Notice
Recent Posts
Recent Comments
Link
지구정복
[수학] 백준 - 소수찾기 본문
728x90
반응형
-자바
package math;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class BJ1978 {
private static BufferedWriter bw =
new BufferedWriter( new OutputStreamWriter(System.out));
private static int n, sum;
private static StringTokenizer st;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt( br.readLine() );
st = new StringTokenizer( br.readLine() );
for( int i=0; i<n; i++ ) {
int num = Integer.parseInt( st.nextToken() );
for( int j=2; j<=num; j++ ) {
if( j!=num && num%j==0 ) break;
else if( j==num && num%j==0 ) sum++;
}
}
bw.write( sum + "\n" );
bw.flush();
bw.close();
br.close();
}
}
-파이썬
n = int(input())
sum = 0
num = [0] + list( map( int, input().split() ) )
for j in range( 1, n+1 ):
for k in range( 2, num[j]+1 ):
if k!=num[j] and num[j]%k==0:
break
elif k==num[j] and num[j]%k==0:
sum += 1
print( sum )
728x90
반응형
'데이터 엔지니어링 정복 > Algorithm' 카테고리의 다른 글
[수학, 구현] 백준 - 문어 (0) | 2021.07.18 |
---|---|
[DP] 백준 - 내리막 길 (0) | 2021.07.17 |
[DP] 백준 - 다리놓기 (0) | 2021.07.17 |
[DP] 백준 - 파스칼의 삼각형 (0) | 2021.07.16 |
[DP] 백준 - 타일 장식물 (0) | 2021.07.16 |
Comments