piyushgoyal443's blog

By piyushgoyal443, history, 5 years ago,

this is my solution and it works


#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;
rem = a % b;
a = div + rem;
}
cout << sum << endl;
return 0;
}




but I saw other people solutions and they have used a formula that calculates answer without any loop

 ans = (a * b — 1)/(b — 1) `