From 40349a7b011327eb4f5515c603f484594e52f8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=80=ED=98=84=EC=84=9C?= <113419425+3veryDay@users.noreply.github.com> Date: Wed, 14 Jan 2026 08:28:23 +0900 Subject: [PATCH] =?UTF-8?q?260114=20:=20[BOJ=209527]=201=EC=9D=98=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20=EC=84=B8=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement a function to calculate the sum of powers of two in a given range. --- _hyunseo/9527.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 _hyunseo/9527.py diff --git a/_hyunseo/9527.py b/_hyunseo/9527.py new file mode 100644 index 00000000..b1a28607 --- /dev/null +++ b/_hyunseo/9527.py @@ -0,0 +1,22 @@ +import sys,math + +sys.setrecursionlimit( 10 ** 8) +input = map(int, input().split()) + +def sum_f ( x) : + if x <= 0 : + return 0 + + seung = int(math.log2(x)) + floor_2pow = 2 ** seung + + # 2, 4, 8, 16, 32 ... + if floor_2pow == x : + return seung*x // 2 + 1 + + diff = x - floor_2pow + # 10 = 8 + 2 + return sum_f(floor_2pow) + diff + sum_f(diff) + +a, b = map(int, input().split()) +print(sum_f(b) - sum_f(a - 1))