/* This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * Calculate the GCD of two numbers. * */ { int x, y; int tmp; int gcd; y = 48128; // 47 * 1024 x = 6439; // 47 * 137 // the rest of the code is parametric on x and y // make sure x is the bigger of the two if (x < y) { tmp = x; x = y; y = tmp; } writeint x; writeint y; // as long as both numbers are larger than 1, while (y > 1) { x %= y; if (x == 0) break; else { // gcd (x, y) = gcd (y, x % y). tmp = x; x = y; y = tmp; } } gcd = y; // print it out writeint gcd; }