Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
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 26 27
28 29 30
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(1978) 소수 찾기 본문

백준 (C++)/Solve

(1978) 소수 찾기

dh-winternagi 2026. 4. 11. 10:13

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

단계별로 풀어보기

9단계(약수, 배수와 소수 1) 4번째

 

 

 

이것도 밀러-라빈 소수판별법 같은 게 있지만 일반적으로는 O(N)이나 O(√N)으로 충분하다.

 

 

 

#include <iostream>
using namespace std;

inline bool isprime(int x){
  if(x==1)  return false;
  
  for(int i=2;i<x;i++)  if(x%i==0)  return false;
  
  return true;
}

int main() {
  int n, ans= 0;
  
  cin >> n;
  
  while(n--){
    int x;
    
    cin >> x;
    
    if(isprime(x))  ans++;
  }
  
  cout << ans;
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(11653) 소인수분해  (0) 2026.04.12
(2581) 소수  (0) 2026.04.12
(9506) 약수들의 합  (0) 2026.04.11
(2501) 약수 구하기  (0) 2026.04.11
(5086) 배수와 약수  (0) 2026.04.11