๐Ÿ—๏ธ Algorithm/๐ŸŸฉ ๋ฐฑ์ค€

๐ŸŸฉ [๋ฐฑ์ค€] [Python] [Gold2] 1300๋ฒˆ_K๋ฒˆ์งธ ์ˆ˜

Dbswnstjd 2023. 2. 20. 08:23

๋ฌธ์ œ

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

 

1300๋ฒˆ: K๋ฒˆ์งธ ์ˆ˜

์„ธ์ค€์ด๋Š” ํฌ๊ธฐ๊ฐ€ N×N์ธ ๋ฐฐ์—ด A๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค. ๋ฐฐ์—ด์— ๋“ค์–ด์žˆ๋Š” ์ˆ˜ A[i][j] = i×j ์ด๋‹ค. ์ด ์ˆ˜๋ฅผ ์ผ์ฐจ์› ๋ฐฐ์—ด B์— ๋„ฃ์œผ๋ฉด B์˜ ํฌ๊ธฐ๋Š” N×N์ด ๋œ๋‹ค. B๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ–ˆ์„ ๋•Œ, B[k]๋ฅผ ๊ตฌํ•ด๋ณด์ž. ๋ฐฐ์—ด A์™€ B

www.acmicpc.net

 

ํ’€์ด

# ๋ฐฑ์ค€ 1300๋ฒˆ ๋ฌธ์ œ - K๋ฒˆ์งธ ์ˆ˜
n, k = int(input()), int(input())
start, end = 1, k

while start <= end:
    mid = (start+end) // 2

    cnt = 0
    for i in range(1, n+1):
        cnt += min(mid//i, n)
    
    if cnt >= k:
        answer = mid
        end = mid - 1
    else:
        start = mid + 1
print(answer)