CP-template-AND-interesting-problems

10368 - Euclid’s Game Problem Link

problem simplified:

Given two initial numbers. two player subtract from the large number in turns. if two numbers are a, b and a > b; then subtraction process is a = a - n*b (where n is an integer such that n*b < a)

Solution Idea

Solution Code(C++)


#include <iostream>
using namespace std;

int main() {
    int a, b;
    while(true){
        cin>>a>>b;
        if((a == 0 && b == 0)) break;
        int turns = 0;
        while(a>0 && b>0){
            if(a < b) swap(a, b);
            int d = a / b;
            if(d > 1 || a%b == 0) break;
            
            a -= (d * b);
            
            turns++;
        }
        if(turns % 2 == 0){
            cout<<"Stan wins"<<endl;
        }else{
            cout<<"Ollie wins"<<endl;
        }
    }
}