அல்கோரிதம்binary decomposition
Binary Decomposition
TT
Testlaa Team
May 14, 2026•1 min read
Bits-ஆக index/value பிரித்தல் (BIT intuition). Powers of two range partition.
Try this in Python
def powers_of_two_sum_to(n: int) -> list[int]:
"""Greedy collect largest power <= remaining (related to binary representation idea)."""
parts: list[int] = []
while n > 0:
p = 1
while p * 2 <= n:
p *= 2
parts.append(p)
n -= p
return parts
print(powers_of_two_sum_to(13))
Key takeaways
- Integer-ன் binary representation உடன் இணை.
- BIT tree எல்லா problem-க்கும் வேண்டாம்.
- சிறிய
nகைமுறை.
Tags:
Binary searchPythonமாணவர்கள்
