Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * author: heWhoCooks
- * created: 2024-12-27 19:11:27
- **/
- #include <bits/stdc++.h>
- using namespace std;
- mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
- #define NeedForSpeed \
- ios_base::sync_with_stdio(false); \
- cin.tie(NULL); \
- cout.tie(NULL);
- #define int long long
- #define all(x) (x).begin(), (x).end()
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef vector<vi> vvi;
- typedef vector<pair<int, int>> vpi;
- #define f first
- #define s second
- #define pb push_back
- #define pf push_front
- #define yes cout << "YES" << endl
- #define no cout << "NO" << endl
- #define endl "\n"
- #define M_PI 3.14159265358979323846L
- const int mod = 1e9 + 7;
- const int INF = 2e18;
- int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
- int steps(int a, int b)
- {
- if (a == 1)
- {
- return b - 1;
- }
- if (a > b)
- {
- return steps(b, a);
- }
- if (b % a)
- {
- return b / a + steps(b % a, a);
- }
- else
- {
- // not reachable as b%a is 0, means one would be zero
- return 1e9;
- }
- }
- void solve()
- {
- int n;
- cin >> n;
- if (n == 1)
- {
- cout << 0 << endl;
- return;
- }
- int ans = INF;
- // calculating the num steps to reach (a, b) where one number is n
- for (int i = 1; i < n; i++)
- {
- ans = min(ans, steps(i, n));
- }
- cout << ans << endl;
- return;
- }
- signed main()
- {
- NeedForSpeed;
- int t = 1;
- // cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment