379A-NEW YEAR CANDLES SOLUTION IN SIMPLE C++

# include<iostream>
using namespace std;
int main ()
{
    int a,b,c,d,e,sum=0;
    cin>>a>>b;
    sum=a;
    c=a/b;
    sum=sum+c;
    e=a%b;
    c=c+e;
   // cout<<c;
    while(c>=b)
    {
       e=c%b;
        c=c/b;
        sum=sum+c;
        //cout<<sum<<endl;
        //e=c%b;
       // cout<<"e=";
        //cout<<e<<endl;
        c=c+e;
        //cout<<"c=";
        //cout<<c<<endl;
        if(c==b)
        {
            sum=sum+1;
            break;
        }

    }
    cout<<sum;


}

Comments

Post a Comment

Popular posts from this blog

codeforces 472A problem solution in simple c/c++

codeforces 339A solution in c/c++

codeforces 520A problem solution in c/c++