Skip to main content

Posts

Showing posts with the label number theory

Fill 2D Space with Hilbert Curve

Light OJ 1278 - Sum of Consecutive Integers

Description Given a positive integer \(n\), you have to find the number of ways you can express \(n\) as sum of consecutive integers. You have to use at least two integers. For example, \(n = 15\) has three solutions, \( (1+2+3+4+5), (4+5+6), (7+8)\). একটা ধনাত্মক সংখ্যা \(n\) দেয়া আছে, তোমাকে বের করতে হবে \(n\) কে কত উপায়ে একাধিক ক্রমিক সংখ্যার যোগফল আকারে লেখা যায়। যেমন, \(n = 15\) কে তিন উপায়ে লেখা যায়, \( (1+2+3+4+5), (4+5+6), (7+8)\). Problem Link আমার সমাধান ধরে নেই \(a,b\in \mathbb{N},a \neq b\) \[ \begin{eqnarray*} &&a + (a+1) + (a+2) + \cdots + b = n\\ &\Rightarrow& \sum_{k = a}^{b} k = n\\ &\Rightarrow& \sum_{k = 1}^{b} k - \sum_{k = 1}^{a-1} k = n\\ &\Rightarrow& \frac{b(b+1)}{2} - \frac{(a-1)(a-1+1)}{2} = n\\ &\Rightarrow& b^2 + b - (a^2-a) = 2n\\ &\Rightarrow& b...