Codeforces 585 C Alice,Bob,Oranges and Apples(法則)


タイトルリンク:Codeforces 585 C Alice,Bob,Oranges and Apples
問題を解く構想.
回数は実はgcd過程で、最後に1を減らします.
コード#コード#
#include 
#include 
#include 
#include 

using namespace std;
typedef long long ll;

ll x, y;
vector ans;

ll gcd (ll a, ll b) {
    if (b == 0) return a;
    ans.push_back(a / b);
    return gcd(b, a % b);
}

int main () {
    ans.clear();
    scanf("%lld%lld", &x, &y);

    ll k = gcd(x, y);
    if (k != 1)
        printf("Impossible
"
); else { int n = ans.size(); ans[n-1]--; int v = x < y; for (int i = 0; i < n; i++) { if (ans[i] == 0) continue; printf("%lld%c", ans[i], 'A' + v); v ^= 1; } printf("
"
); } return 0; }