Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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 31
Tags
more
Archives
Today
Total
관리 메뉴

xcc1

백준 2581번:소수(2) 본문

백준

백준 2581번:소수(2)

xcc1 2021. 11. 4. 13:16

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

 

2581번: 소수

M이상 N이하의 자연수 중 소수인 것을 모두 찾아 첫째 줄에 그 합을, 둘째 줄에 그 중 최솟값을 출력한다.  단, M이상 N이하의 자연수 중 소수가 없을 경우는 첫째 줄에 -1을 출력한다.

www.acmicpc.net

 

 

 

전체코드

 

t = int(input())
T = int(input())
total = []


for N in range(t,T+1):
    h = 0
    if N > 1:
        for n in range(2,N):
            if N % n == 0:
                h += 1
                break
        if h == 0:
            total.append(N)

if sum(total) > 0:
    print(sum(total))
    print(min(total))
else:
    print(-1)

'백준' 카테고리의 다른 글

백준 1978번:소수찾기  (0) 2021.11.03
백준 2839번:설탕배달  (0) 2021.10.30
백준 10250:ACM 호텔  (0) 2021.10.28
백준 1193번  (0) 2021.10.27
백준 문제별풀이 7단계(파이썬)  (0) 2021.09.04