-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC+=.cpp
More file actions
31 lines (24 loc) · 862 Bytes
/
C+=.cpp
File metadata and controls
31 lines (24 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// we have a , b , n
//we have to make either of a or b > n and return the minimum steps to do so
//only operations allowed are a += b or b += a
#include <bits/stdc++.h>
using namespace std;
int main() {
int testcases;
cin >> testcases;
while (testcases--) {
int a, b, n;
cin >> a >> b >> n;
// Ensure a is the smaller value and b is the larger value
if (a > b) swap(a, b);
int steps = 0;
// Keep adding the smaller value to the larger one until either exceeds n
while (b <= n) {
a += b; // Add the smaller value to the larger one
steps++;
if (a > n) break; // If the new value of a exceeds n, break the loop
swap(a, b); // Swap the values to maintain a as the smaller and b as the larger
}
cout << steps << endl;
}
}