// Arup Guha
// 1/23/2015
// Solution to 2013 MCPC Problem B: Round Robin

import java.util.*;

public class b {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		while (n != 0) {
			int count = stdin.nextInt();

			// Initial set up.
			ArrayList<Integer> steps = new ArrayList<Integer>();
			for (int i=0; i<n; i++)
				steps.add(0);
			int pos = 0;
			boolean flag = true;

			// Keep playing while there are unequal number of turns.
			while (!same(steps) || flag) {

				for (int i=0; i<count; i++) {
					steps.set(pos, steps.get(pos) + 1);
					if (i < count-1) pos = (pos+1)%n;
				}
				steps.remove(pos);
				n--;
				pos = pos%n;
				flag = false;
			}

			// Result.
			System.out.println(steps.size()+" "+steps.get(0));

			// Get next case.
			n = stdin.nextInt();
		}
	}

	// Returns true iff each item in list is the same.
	public static boolean same(ArrayList<Integer> list) {
		for (int i=1; i<list.size(); i++)
			if (!list.get(i).equals(list.get(0)))
				return false;
		return true;
	}
}