https://www.acmicpc.net/problem/4134
4134번: 다음 소수
첫째 줄에 테스트 케이스의 개수가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있고, 정수 n이 주어진다.
www.acmicpc.net
# 4134 - Python 3
import sys
input = sys.stdin.readline
def isPrime(n): # 소수 판별 함수 선언
if n == 0 or n == 1:
return False
else:
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
n = int(input())
for _ in range(n):
x = int(input())
while True:
if isPrime(x) == True:
print(x)
break
else:
x += 1'코딩' 카테고리의 다른 글
| [Python] 백준 #17103. 골드바흐 파티션 (1) | 2023.03.21 |
|---|---|
| [Python] 백준 #4948. 베르트랑 공준 (0) | 2023.03.20 |
| [Python] 백준 #2485. 가로수 (0) | 2023.03.20 |
| [Python] 백준 #1735. 분수 합 (0) | 2023.03.20 |
| [Python] 백준 #13241. 최소공배수 (0) | 2023.03.20 |