how to derive New Year Candles formula
Difference between en1 and en2, changed 58 character(s)
this is my solution and it works↵

<pre><code>↵
#include< < iostream >↵

using namespace std;↵

int main()↵
{↵
    int a, b, div, rem;↵
    cin >> a >> b;↵
    int sum = a;↵
    while(a >= b)↵
    {↵
        div = a / b;↵
        sum += div;↵
        mod = a % b;↵
        a = div + rem;↵
    }↵
    cout << sum << endl;↵
    return 0;↵
}↵
`↵
</code></pre>

but I saw other people solutions and they have used a formula that calculates answer without any loop↵
<pre><code>
ans = (a * b &mdash; 1)/(b &mdash; 1)↵
</code></pre>↵

Can someone please help me how to get this formula?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English piyushgoyal443 2016-08-31 04:13:02 78
en2 English piyushgoyal443 2016-08-30 17:47:44 58 Tiny change: 'codeio' -
en1 English piyushgoyal443 2016-08-30 17:35:19 563 Initial revision (published)