Skip to content

Instantly share code, notes, and snippets.

@task4233
Created February 7, 2019 01:04
Show Gist options
  • Save task4233/353793c3588c494c034bbb20cccacd9b to your computer and use it in GitHub Desktop.
Save task4233/353793c3588c494c034bbb20cccacd9b to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
using int64 = int64_t;
int f(int x, int y){
int mx = max(x, y);
int mn = min(x, y);
if (mx == mn) return x;
return f(mn, mx-mn) + 2 * mn;
}
int main(){
int n, x;
cin >> n >> x;
int ans = x + (n-x) + f(x, n-x);
cout << ans << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment