#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
//#include<ctype.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
//#define MAX(a,b) a>b?a:b
//#define MIN(a,b) a<b?a:b

int main() {
	int n, p,b;
	for (; ~fscanf(stdin, "%d%d", &n, &p), n, p; P(d, b)) {
		b = 0;
		int a[50] = {},
			c = p;
		while (1) {
			b %= n;
			if (c == 0) c = a[b], a[b] = 0;
			else c--, a[b]++;
			if (a[b] == p)break;
			b++;
		}
	}
	return 0;
}