diff --git "a/jaykxo/week07/11659_\352\265\254\352\260\204_\355\225\251_\352\265\254\355\225\230\352\270\260_4.py" "b/jaykxo/week07/11659_\352\265\254\352\260\204_\355\225\251_\352\265\254\355\225\230\352\270\260_4.py" new file mode 100644 index 0000000..60aea3a --- /dev/null +++ "b/jaykxo/week07/11659_\352\265\254\352\260\204_\355\225\251_\352\265\254\355\225\230\352\270\260_4.py" @@ -0,0 +1,26 @@ +# 11659 구간 합 구하기 4 +# Python3, 메모리: 52312 KB, 시간: 204 ms +# PyPy3, 메모리: 121852 KB, 시간: 144 ms + +import sys +input = sys.stdin.readline + +N, M = map(int, input().strip().split()) +arr = list(map(int, input().split())) + +# 누적합 배열 초기화 (0번째 인덱스는 0으로 패딩) +prefix_sum = [0] * (N + 1) + +# (1 ~ i)까지의 누적합 계산 +for i in range(1, N + 1): + prefix_sum[i] = prefix_sum[i - 1] + arr[i - 1] + +answers = [] + +# (i ~ j) 구간합 = prefix_sum[j] - prefix_sum[i - 1] +for _ in range(M): + i, j = map(int, input().split()) + s = prefix_sum[j] - prefix_sum[i - 1] + answers.append(s) + +print('\n'.join(map(str, answers))) \ No newline at end of file diff --git "a/jaykxo/week07/11660_\352\265\254\352\260\204_\355\225\251_\352\265\254\355\225\230\352\270\260_5.py" "b/jaykxo/week07/11660_\352\265\254\352\260\204_\355\225\251_\352\265\254\355\225\230\352\270\260_5.py" new file mode 100644 index 0000000..6af70fc --- /dev/null +++ "b/jaykxo/week07/11660_\352\265\254\352\260\204_\355\225\251_\352\265\254\355\225\230\352\270\260_5.py" @@ -0,0 +1,41 @@ +# 11660 구간 합 구하기 5 +# Python3, 메모리: 116164 KB, 시간: 712 ms +# PyPy3, 메모리: 136748 KB, 시간: 256 ms + +import sys +input = sys.stdin.readline + +# 한 번 함수로 맨들어 보고 싶어서 해봤읍니다,,,, +def build_prefix(arr): + """2차원 누적합 테이블 생성""" + N = len(arr) - 1 + ps = [[0] * (N + 1) for _ in range(N + 1)] + for i in range(1, N + 1): + for j in range(1, N + 1): + # (1,1)~(i,j) 구간합 = 위 + 왼쪽 - 겹친부분 + 현재값 + ps[i][j] = ps[i-1][j] + ps[i][j-1] - ps[i-1][j-1] + arr[i][j] + return ps + +def range_sum(ps, x1, y1, x2, y2): + """(x1,y1)~(x2,y2) 구간합 반환""" + # 전체 - 위쪽 - 왼쪽 + 겹친부분 + return ps[x2][y2] - ps[x1-1][y2] - ps[x2][y1-1] + ps[x1-1][y1-1] + +# -------------------- main -------------------- +N, M = map(int, input().split()) + +# 1-index 접근을 위한 0 패딩 +arr = [[0] * (N + 1)] +for _ in range(N): + arr.append([0] + list(map(int, input().split()))) + +# 누적합 생성 +ps = build_prefix(arr) + +# 구간합 계산 +out = [] +for _ in range(M): + x1, y1, x2, y2 = map(int, input().split()) + out.append(str(range_sum(ps, x1, y1, x2, y2))) + +print("\n".join(out)) \ No newline at end of file diff --git "a/jaykxo/week07/1929_\354\206\214\354\210\230_\352\265\254\355\225\230\352\270\260.py" "b/jaykxo/week07/1929_\354\206\214\354\210\230_\352\265\254\355\225\230\352\270\260.py" new file mode 100644 index 0000000..6985415 --- /dev/null +++ "b/jaykxo/week07/1929_\354\206\214\354\210\230_\352\265\254\355\225\230\352\270\260.py" @@ -0,0 +1,25 @@ +# 1929 소수 구하기 +# Python3, 메모리: 39656 KB, 시간: 3340 ms +# PyPy3, 메모리: 116148 KB, 시간: 796 ms + +import sys +input = sys.stdin.readline + +def is_prime(x): + if x < 2: + return False + for j in range(2, int(x ** 0.5) + 1): + if x % j == 0: + return False + return True # 위 조건 통과 시 소수 + +# -------------------- main -------------------- + +M, N = map(int, input().split()) +primes = [] + +for i in range(M, N + 1): + if is_prime(i): + primes.append(i) + +print('\n'.join(map(str, primes))) \ No newline at end of file diff --git "a/jaykxo/week07/2581_\354\206\214\354\210\230.py" "b/jaykxo/week07/2581_\354\206\214\354\210\230.py" new file mode 100644 index 0000000..e94ef68 --- /dev/null +++ "b/jaykxo/week07/2581_\354\206\214\354\210\230.py" @@ -0,0 +1,32 @@ +# 2581 소수 +# Python3, 메모리: 32412 KB, 시간: 40 ms +# PyPy3, 메모리: 110736 KB, 시간: 100 ms + +import sys +input = sys.stdin.readline + +def is_prime(x): + if x < 2: + return False + for j in range(2, int(x ** 0.5) + 1): + if x % j == 0: + return False + return True # 위 조건 통과 시 소수 + +# -------------------- main -------------------- + +M = int(input()) +N = int(input()) + +primes = [] + +for i in range(M, N + 1): + if is_prime(i): + primes.append(i) + +if not primes: + print(-1) + +else: + print(sum(primes)) + print(min(primes)) \ No newline at end of file