Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		n, _ := strconv.Atoi(chunks[0])
		p, _ := strconv.Atoi(chunks[1])
		cnts := make([]int, n, n)
		for i := 0; true; i++ {
			j := i % n
			if p == 0 {
				p, cnts[j] = cnts[j], 0
			} else {
				cnts[j]++
				p--
			}

			if p == 0 {
				noneCnt := 0
				winner := 0
				for j, c := range cnts {
					if c == 0 {
						noneCnt++
					} else {
						winner = j
					}
				}
				if noneCnt == n-1 {
					fmt.Println(winner)
					break
				}
			}
		}
	}
}

C++: #include<iostream>
using namespace std;

int start = 0;
int stone;

void odd(int n[50], int ppl){
//	cout<<n[0] << " " << n[1] << " " << n[2] << " " << stone << endl;
	if(stone == 0){
//		cout << "Yes" << start << endl;
		stone = n[start];
		n[start] = 0;
		start ++;
			if(start == ppl){
				//cout << "li" << endl;
				start = 0;
			}
	}else{
		int number;
		number = stone/ppl;
		//cout << "--" << number << endl;
		for(int i = 0; i < ppl; i++){
			n[i] += number;
		}
		number = stone % ppl;
		for(int i=0; i < number; i++){
			n[start] ++;
			start++;
			if(start == ppl){
	//			cout << "li" << endl;
				start = 0;
			}
		}
		stone=0;
	}
}


int main(){
	int ppl;
	int hantei = 1;
	int i;
	int original;

	while(cin >> ppl >> stone, ppl){
//	cout<<n[0] << " " << n[1] << " " << n[2] << " " << endl;
		hantei = 1;
	int n[50] = {0};
		start = 0;
		original = stone;
		while(hantei){
			odd(n, ppl);
			for(i = 0; i < ppl; i++){
				if(n[i] == original){
					 hantei = 0;
					 break;
				}

			}
		}
		cout << i << endl; 
	}

}

C++: #include <bits/stdc++.h>
using namespace std;

#define pb         push_back

const int INF = 1000000000;
const int MOD = 1000000007;

int main(void) {
	while(1){
		int n, p;
		int st[100] = {0};
		cin >> n >> p;
		if(n == 0 && p == 0) break;

		int i = 0;
		int wan = p;
		while(1){
			if(wan > 0){
				st[i]++;
				wan--;
				if(st[i] == p){
					printf("%d\n", i);
					break;
				}
			}else{
				wan += st[i];
				st[i] = 0;
			}
			/*
			for(int j=0; j<n; j++){
				printf("%d:%d\n", j, st[j]);
			}
			puts("");
			*/
			i++;
			i%=n;
		}
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;

void main() {
	int n, p;

	while (1) {
		int flag = 0;
		int player[50] = { 0 };
		cin >> n >> p;
		if (n == 0 && p == 0) break;
		int p_max = p;

		while (1) {
			for (int j = 0; j < n; j++) {
				if (p != 0) player[j] += 1, p--;
				else p = player[j], player[j] = 0;
				if (player[j] == p_max) {
					flag = -1;
					cout << j << endl;
					break;
				}
			}
			if (flag == -1) break;
		}
	}
}

C++: #include<cstdio>
#include<cstring>

int n,p;
int d[100];
int main(void){
	while(1){
		scanf("%d %d",&n,&p);
		memset(d,0,sizeof(d));
		if(n+p==0)break;
		int i=0,mp=p;
		while(1){
			if(p==0){
				if(d[i]==mp)break;
				p+=d[i];
				d[i]=0;
			}else d[i]++,p--;
			i=(i+1)%n;
		}
		printf("%d\n",i);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;

int main(){
int n,p;
int c[50];
for(;;){
cin >> n >> p;
if(!n && !p)break;
for(int i=0;i<n;i++)c[i] = 0;

int pos = -1;
for(;;){
pos = (pos+1)%n;
if(p){
c[pos]++;
p--;
}else{
p = c[pos];
c[pos] = 0;
}
if(!p){
int cnt = 0;
for(int i=0;i<n;i++)
if(c[i])cnt++;
if(cnt==1)break;
}
}
cout << pos << endl;
}
}

C++: #include <iostream>
using namespace std;
int main(){
  int n,p;
  for(;;){
    cin >>n >> p;
    if(n == 0 && p == 0)break;
    int human[n];
    for(int i = 0;i < n;i++){
      human[i]=0;
    }
    int stone = p;
    int turn = 0;
    for(;;){
      if(!stone){
        stone += human[turn];
        human[turn] = 0;
      } else if(stone > 0){
        if(!(--stone) && (++human[turn]) == p){
          cout << turn << endl;
          break;
        }
      }
      if(++turn >= n) turn = 0;
    }
  }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
	int N,P;
	while(cin>>N>>P,N||P){
		int wan,cnt[50]={};
		wan = P;
		for(int i=0;;i=(i+1)%N){
			if(wan==0){
				wan += cnt[i]; cnt[i] = 0;
			}
			else{
				cnt[i]++; wan--;
				if(cnt[i]==P){
					printf("%d\n",i); break;
				}
			}
		}
	}
	return 0;
}

C++: #include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(itr,data) for(__typeof((data).begin()) itr=(data).begin();itr!=(data).end();++itr)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

int n,p;

bool check(int *a) {
    int cnt=0;
    rep(i,n) if(a[i]!=0) cnt++;
    return cnt==1;
}

void solve() {
    int ary[100]={};
    int wan=p;

    int index = 0;
    while(true) {
        if(wan==0) {
            if(p==ary[index]) break;
            wan = ary[index];
            ary[index] = 0;
        }
        else {
            wan--;
            ary[index]++;
        }
        index++;
        index%=n;
    }
    //index=index+n-1;
    //index%=n;
    cout<<index<<endl;


}

int main() {
    while(cin>>n>>p){
        if(!(n+p)) return 0;
        solve();
    }
    return 0;
}

C++: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double EPS = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int n, p;

int main() {
	// cin.tie(0); // tie
	// ios::sync_with_stdio(false); // sync
	while (cin >> n >> p, n || p) {
		int tmp = p;
		vector<int> a(n, 0);
		for (int i = 0; i < n; ++i) {
			if (p != 0) {
				a[i]++;
				p--;
				if (p == 0 && a[i] == tmp) {
					cout << i << endl;
					break;
				}
			} else {
				p = a[i];
				a[i] = 0;
			}
			if (i == n - 1) i = -1;
		}
	}
	return 0;
}