輾轉相除法
Use the Euclidean algorithm.

ZeroJudge Link (Zh)

#include <stdio.h>

main() {
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    while (b != 0) {
      if (a < b) { a ^= b; b ^= a; a ^= b; }
      a -= b;
    }
    printf("%d\n", a);
  }
  return 0;
}