File tree Expand file tree Collapse file tree 3 files changed +87
-0
lines changed
Expand file tree Collapse file tree 3 files changed +87
-0
lines changed Original file line number Diff line number Diff line change 1+ # pypy3
2+ # 시간(ms) : 92
3+ # 공간(KB) : 109544
4+
5+ import sys
6+ input = sys .stdin .readline
7+
8+ n , K = map (int , input ().strip ().split ())
9+
10+ sieve = [True ] * (n + 1 )
11+ sieve [0 ] = sieve [1 ] = False
12+
13+ def find_kth_removed (n , K ) :
14+ k = 0
15+ for i in range (2 , n + 1 ): # 소수를 포함하여 지워지는 수를 확인해야하므로 n까지 탐색
16+ if sieve [i ]: # 소수라면 본인과 배수 제거
17+ for j in range (i , n + 1 , i ):
18+ if sieve [j ]:
19+ sieve [j ] = False
20+ k += 1
21+ if k == K : return j
22+ print (find_kth_removed (n , K ))
Original file line number Diff line number Diff line change 1+ # pypy3
2+ # 시간(ms) : 152
3+ # 공간(KB) : 118540
4+ #
5+ # 공유 :
6+ # - gpt가 파이썬은 인덱스를 음수로 반복적으로 접근하면 내부적으로 인덱스 변환을 계속 해야 하므로 느리다함
7+ # 이 문제 기준으로는 8ms 차이라서 크게 신경 안써도 될듯 (백만 단위 이상 인덱싱에서 3~5% 정도 느리다고)
8+
9+ import sys
10+ input = sys .stdin .readline
11+
12+ n , h = map (int , input ().strip ().split ())
13+
14+ top = [0 ] * (h + 1 ) # 종유석
15+ bottom = [0 ] * (h + 1 ) # 석순
16+
17+ for _ in range (n // 2 ) : # 종유석, 석순 각각 같은 길이 카운팅
18+ bottom [int (input ())] += 1
19+ top [- int (input ())] += 1
20+
21+ for i in range (1 , h + 1 ) : # 종유석, 석순 각각 누적합을 통해 구간에 따른 hit 구하기
22+ top [i ] += top [i - 1 ]
23+ bottom [- (i + 1 )] += bottom [- i ]
24+
25+ min_hit = n # 최소 hit
26+ min_hit_cnt = 1 # 최소 hit 개수
27+ for i in range (1 , h + 1 ) :
28+ hit = top [i ] + bottom [i ] # 종유석, 석순 합쳐서 최종 hit 구하기
29+ if min_hit > hit :
30+ min_hit = hit
31+ min_hit_cnt = 1
32+ elif min_hit == hit :
33+ min_hit_cnt += 1
34+
35+ print (min_hit , min_hit_cnt )
36+
37+
Original file line number Diff line number Diff line change 1+ # pypy3
2+ # 시간(ms) : 316
3+ # 공간(KB) : 119244
4+
5+ import sys
6+ input = sys .stdin .readline
7+ MAX = 1_000_000
8+
9+ def goldbach_conjecture_check (n ) :
10+ for i in range (3 , n - 2 ) : # 홀수 소수 합이 n이 되는지 확인
11+ if sieve [i ] and sieve [n - i ]:
12+ return f"{ n } = { i } + { n - i } "
13+ return "Goldbach's conjecture is wrong."
14+
15+ # MAX 값 기준 에라토스테네스의 체 생성
16+ sieve = [True ] * (MAX + 1 )
17+ sieve [0 ] = sieve [1 ] = False
18+
19+ for i in range (2 , int (MAX ** 0.5 ) + 1 ):
20+ if sieve [i ]: # 소수라면 배수 제거
21+ for j in range (i * i , MAX + 1 , i ): # i*i보다 작은 배수는 중복 처리이기 때문에 i*i 부터 확인
22+ sieve [j ] = False
23+
24+ # 골드바흐의 추측 검증
25+ while True :
26+ n = int (input ())
27+ if n == 0 : break
28+ print (goldbach_conjecture_check (n ))
You can’t perform that action at this time.
0 commit comments