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
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; }
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.