Problem:
Problem A: Greatest Common Divisor

Please find the greatest common divisor of two natural numbers. A clue is: The Euclid's algorithm is a way to resolve this task.

Input

The input file consists of several lines with pairs of two natural numbers in each line. The numbers do not exceed 100000.

The number of pairs (datasets) is less than 50.

Output

Your program has to print the greatest common divisor for each pair of input numbers. Print each result on a new line.

Sample Input

57 38
60 84

Output for the Sample Input

19
12

Solution in JAVA (judge verdict: Accepted)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine()) != null) {
            String[] tokens = line.split(" ");
            int a = Integer.parseInt(tokens[0]);
            int b = Integer.parseInt(tokens[1]);
            int c = greateCommonDivisor(a, b);
            System.out.println(c);
        }
    }

    static int greateCommonDivisor(int a, int b) {
        if (a % b == 0) {
            return b;
        } else {
            int c = Math.abs(a - b);
            int d = Math.min(a, b);
            return greateCommonDivisor(Math.max(c,d), Math.min(c,d));
        }
    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(BufferedReader br) throws IOException {
        String[] lines = br.readLine().split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static int ip(BufferedReader s) throws IOException {
        return Integer.parseInt(s.readLine());
    }
}