From 4a543d59cf57fbfba0c9bb954260018c8cc0bfcb Mon Sep 17 00:00:00 2001 From: SamaKool Date: Thu, 23 Oct 2025 12:26:37 +0530 Subject: [PATCH] Added solution to Bear and Big Brother problem. --- .../Programs/C++/BearAndBigBrother.cpp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Domains/CompetitiveProgramming/Programs/C++/BearAndBigBrother.cpp diff --git a/Domains/CompetitiveProgramming/Programs/C++/BearAndBigBrother.cpp b/Domains/CompetitiveProgramming/Programs/C++/BearAndBigBrother.cpp new file mode 100644 index 00000000..a94289d2 --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/C++/BearAndBigBrother.cpp @@ -0,0 +1,66 @@ +/* +Problem: Bear and Big Brother +Platform: Codeforces +Problem Code: 791A +Difficulty: Easy (800 rated) +Link: https://codeforces.com/problemset/problem/791/A + +Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. + +Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. + +Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. + +After how many full years will Limak become strictly larger (strictly heavier) than Bob? + +Input +The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively. + +Output +Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. + +Examples: + +Input: +4 7 +Output: +2 + +Input: +4 9 +Output: +3 + +Input: +1 1 +Output: +1 + +Approach: +1. We loop till Weight of Limak is > Weight of Bob + +Time Complexity: O(n) +Space Complexity: O(1) + +Contributor: SamaKool +*/ + + +#include +using namespace std; + +int main(){ + int a, b, x, y, t; + cin >> a; + cin >> b; + x = a; + y = b; + t = 0; + while(x <= y){ + x *= 3; + y *= 2; + t++; + } + cout<