Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions INSEA-99/week07/11659_구간_합_구하기_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# pypy3
# 시간(ms) : 172
# 공간(KB) : 127164

import sys
input = sys.stdin.readline

n, m = map(int, input().strip().split())
sum_arr = [0] # 누적합 리스트
arr = list(map(int, input().strip().split())) # input list

sum = 0
for x in arr : # 누적합 구하기
sum+=x
sum_arr.append(sum)

for _ in range(m) : # 구간합 구하기
l, r = map(int, input().strip().split())
print(sum_arr[r] - sum_arr[l-1])
38 changes: 38 additions & 0 deletions INSEA-99/week07/11660_구간_합_구하기_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# pypy3
# 시간(ms) : 276
# 공간(KB) : 120516
#
# 공유 :
# - enumerate : 파이썬에서 반복문을 쓸 때, 인덱스(index)와 값(value)를 동시에 얻을 수 있게 해주는 내장 함수
#
# fruits = ['apple', 'banana', 'cherry']
#
# ex1)
# for i, fruit in enumerate(fruits):
# print(i, fruit)
# ->
# 0 apple
# 1 banana
# 2 cherry
#
# ex2)
# for i, fruit in enumerate(fruits, start=1):
# print(i, fruit)
# ->
# 1 apple
# 2 banana
# 3 cherry

import sys
input = sys.stdin.readline

n, m = map(int, input().strip().split())
sum_arr = [[0]*(n + 1) for _ in range(n + 1)] # 누적합 리스트

for i in range(1, n + 1) : # 누적합 구하기
for j, x in enumerate(list(map(int, input().strip().split())), start=1) :
sum_arr[i][j] = x + sum_arr[i-1][j] + sum_arr[i][j-1] - sum_arr[i-1][j-1]

for _ in range(m) : # 누적합 이용해서 답 구하기
x1, y1, x2, y2 = map(int, input().strip().split())
print(sum_arr[x2][y2] - sum_arr[x2][y1-1] - sum_arr[x1-1][y2] + sum_arr[x1-1][y1-1])
19 changes: 19 additions & 0 deletions INSEA-99/week07/1929_소수_구하기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# pypy3
# 시간(ms) : 136
# 공간(KB) : 123940

import sys
input = sys.stdin.readline

m, n = map(int, input().strip().split())

sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False

for i in range(2, int(n ** 0.5) + 1):
if sieve[i]: # 소수라면 배수 제거
for j in range(i * i, n + 1, i): # i*i보다 작은 배수는 중복 처리이기 때문에 i*i 부터 확인
sieve[j] = False

primes = [i for i in range(m, n + 1) if sieve[i]] # 범위 내 소수들
print(*primes, sep='\n')
22 changes: 22 additions & 0 deletions INSEA-99/week07/2581_소수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# pypy3
# 시간(ms) : 92
# 공간(KB) : 109544


import sys
input = sys.stdin.readline

m = int(input())
n = int(input())

sieve = [True] * (n + 1)
sieve[0] = sieve[1] = False

for i in range(2, int(n ** 0.5) + 1):
if sieve[i]: # 소수라면 배수 제거
for j in range(i * i, n + 1, i): # i*i보다 작은 배수는 중복 처리이기 때문에 i*i 부터 확인
sieve[j] = False

primes = [i for i in range(m, n + 1) if sieve[i]] # 범위 내 소수들

print(-1 if not primes else f"{sum(primes)}\n{primes[0]}")