#include <iostream>
using namespace std;

// gcd example program

long gcd(long,long);

int main() {
  long x, y;

  cout << "enter two values and gcd will be returned" << endl;
  cin >> x >> y;

  while(x != 0) {
    cout << "the gcd of " << x << " and " << y << " is " << gcd(x,y) << endl;
    cout << "more?  Enter 0 0 to quit" << endl;
    cin >> x >> y;
  }
}

// a and b can be input in any order, ie 2/8 or 8/2

long gcd( long a, long b) {
  long x, y, r;

  if ( a < b) { x = b; y = a;}
    else {x = a; y = b;}

  while (y != 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}