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 님의 블로그

(4134) 다음 소수 본문

백준 (C++)/Solve

(4134) 다음 소수

dh-winternagi 2026. 4. 15. 07:50

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

단계별로 풀어보기

15단계(약수, 배수와 소수 2) 5번째

 

 

 

브루트 포스로 풀어도 된다는 증명이 있긴 한데 알고리즘보다 정수론 지식이 더 필요한 증명 같아서 패스. 그냥 되겠거니 하고 풀면 될 것 같다.

그것보다 1 이하 예외처리를 안해서 틀렸다.

 

 

 

#include <iostream>
using namespace std;
typedef unsigned int ui;

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

int main() 
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  int T;
  
  cin >> T;
  
  while(T--){
    ui n;
    
    cin >> n;
    
    while(true){
      if(isprime(n)){
        cout << n << "\n";
        
        break;
      }
      
      n++;
    }
  }
  
  return 0;
}

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

(4948) 베르트랑 공준  (0) 2026.04.15
(1929) 소수 구하기  (0) 2026.04.15
(2485) 가로수  (0) 2026.04.15
(1735) 분수 합  (0) 2026.04.14
(13241) 최소공배수  (0) 2026.04.14