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;↵
modrem = a % b;↵
a = div + rem;↵
}↵
cout << sum << endl;↵
return 0;↵
}↵
↵
[link to the problem] (http://codeforces.com/problemset/problem/379/A)↵
`↵
</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 — 1)/(b — 1)↵
</code></pre>↵
↵
Can someone please help me how to get this formula?
↵
<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;↵
a = div + rem;↵
}↵
cout << sum << endl;↵
return 0;↵
}↵
↵
[link to the problem] (http://codeforces.com/problemset/problem/379/A)↵
`↵
</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 — 1)/(b — 1)↵
</code></pre>↵
↵
Can someone please help me how to get this formula?