Codeforces Problem 791/A. Bear and Big Brother solution with CPP 100% Accepted

Before seeking assistance, it is advisable to make an effort to solve the problem yourself. This can involve researching the problem online, reviewing relevant documentation, and attempting to apply your knowledge to find a solution. By trying to solve the problem first, you can gain a better understanding of the issue and also improve your problem-solving skills. It also demonstrates to others that you have made an effort to solve the problem before seeking help.

Codeforces Problem 791/A. Bear and Big Brother solution with CPP

Question link

Code explanation

The given program takes two integer inputs ‘a’ and ‘b’ from the user, then runs a loop that repeats until ‘a’ becomes greater than ‘b’. Inside the loop, the values of ‘a’ and ‘b’ are updated by multiplying ‘a’ by 3 and ‘b’ by 2 respectively. The loop also contains an if statement to check if ‘a’ is greater than ‘b’, if so, the loop terminates using the break statement. The loop counter ‘i’ keeps track of the number of iterations it takes for ‘a’ to become greater than ‘b’. Finally, the program outputs the value of ‘i’.

Bear and Big Brother

#include<iostream>

using namespace std;
int main()
{
int a,b,i;
cin>>a>>b;

for(i=1;;i++){
a=a*3; b=b*2;
if(a>b)

break;
}

cout<<i;

}

Codeforces 236A Boy or Girl Solution

1 thought on “Codeforces Bear and Big Brother solution”

Leave a Comment