Search
Duplicate
📗

다음 소수

주차
문제번호
4134
언어
C++
티어
실버
유형
수학
브루트포스
정수론
소수 판정
nj_Blog
nj_상태
이해도
100%
풀이
사람
이해도 2
13 more properties

문제접근

입력 받은 수부터 소수판정

놓쳤던 부분

코드

2032 KB

268 ms

#include <iostream> #include <cmath> using namespace std; int main(void) { int t; long long n; bool flag; ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> t; for (int i = 0; i < t; i++) { cin >> n; long long num = n; if (num <= 1) cout << "2\n"; else { while (true) { flag = false; for (int j = 2; j <= sqrt(num); j++) { if (num % j == 0) { flag = true; break ; } } if (!flag) { cout << num << "\n"; break ; } num++; } } } return (0); }
C++
복사