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>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int n, p;
        cin >> n >> p;
        const int P = p;
        if (n == 0 and p == 0) {
            break;
        }
        int s = 0;
        vector<int> stone(n, 0);
        while (true) {
            if (p == 0) {
                p = stone[s];
                stone[s] = 0;
            } else {
                stone[s]++;
                p--;
                if (p == 0 and stone[s] == P) {
                    break;
                }
            }
            s = (s == n - 1) ? 0 : s + 1;
        }
        cout << s << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class person{
	private: int sum;
	public: person(int sum):sum(sum){}
		void setKoishi(){
			sum++;
		}
		int clear(){
			int res=sum;
			sum=0;
			return res;
		}
		bool haveAllKoishi(int allKoishi){
			return sum == allKoishi;
		}
};

class vessel{
	private:int sum;
	public:vessel(int sum):sum(sum){}
	       void setKoishi(int koishi){
			sum=koishi;
	       }
	       void getKoishi(){
			sum--;
	       }
	       bool isNothing(){
			return sum==0;
	       }
};
int main(){
	int sum;
	int n,p;
	while((cin>>n>>p)&&(n!=0)&&(p!=0)){
		vector<person> candidate;
		vessel aVessel(p);
		for(int i=0;i<n;i++){
			candidate.emplace_back(0);
		}
		for(int cnt=0;cnt<1000000;cnt++){
			if(!aVessel.isNothing()){
				aVessel.getKoishi();
				candidate[cnt%n].setKoishi();
			}else{
				if(candidate[cnt%n].haveAllKoishi(p)){
					cout << cnt%n << endl;
					break;
				}else{
					aVessel.setKoishi(candidate[cnt%n].clear());
				}
			}
		}
	}
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <stack>
#include <queue>

#define N 64

using namespace std;

int main(void) {
	while(1) {
		int man[N] = {0};
		int bowl, now = 0;
		int n, p;
		bool endflag;
		scanf("%d %d", &n, &p);
		if(n == 0 && p == 0) break;
		bowl = p;
		while(1) {
			if(bowl != 0) {
				man[now]++;
				bowl--;
			} else {
				bowl = man[now];
				man[now] = 0;
			}

			if(bowl == 0) {
				endflag = true;
				for(int i = 0; i < n; i++) {
					if(i != now && man[i] != 0) {
						endflag = false;
						break;
					}
				}
				if(endflag) break;
			}
			now = (now + 1) % n;
		}

		printf("%d\n", now);
	}
	return 0;
}

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

int main(){
   while(1){
      int n, p, kei, name=100, hito[50]= {};
      cin>>n>>p;
      kei = p;
      if(n == 0 && p == 0) break;
 
      while(1){
              for(int j=0;j<n;j++){
                     if(p != 0){
                           hito[j]+=1;
                           p-=1;
                     }
                     else{ 
                           p += hito[j];
                           hito[j] = 0;
                     }
                     if(hito[j] == kei) name = j;
               
                     if(name != 100)  break;
               }
               if(name != 100) break;
       
       }
       cout<<name<<endl;
   }     
   return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int num,i,j;
	
	for(;;)
	{
		int n[55]={0},p[4];
		cin >> num >> p[0] ;
		if(num==0 && p[0]==0)
			break;
		
		p[1]=p[0];
		for(i=0;;i++)
		{
			if(i==num)
				i-=num;
			if(p[1]!=0)
			{
				n[i]++;
				p[1]--;
			}
			else
			{
				p[1]=n[i];
				n[i]=0;
			}
			if(n[i]==p[0])
				break;
		}
		cout << i << endl;
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<ll,ll> ;
const ll INF = 10000000000;
const int MOD = 1000000007;

int main(){
    while(1){
        int n,p;
        cin >> n >> p;
        if(n == 0 && p == 0) break;
        int cnt = p;
        vector<int> a(n,0);
        int i = 0;
        while(1){
            if(cnt > 0) --cnt,++a[i];
            else cnt+=a[i],a[i]=0;
            if(a[i] == p){
                cout << i << endl;
                break;
            }
            ++i;
            if(i==n) i=0;
        }
    }
    return 0;
}

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

int main(void){
  while(1){
    int stone[50];
    for(int k = 0 ; k < 50 ; k++){stone[k] = 0;}

    int bowl;
    int n, p;  // n：候補者人数，p：小石の総数
    cin >> n;
    cin >> p;

    if(n == 0 && p == 0){return 0;}

    bowl = p;

    bool flg = true;
    int ans;

    for(int i = 0 ; flg ; i = (i+1) % n){

      if(bowl == 0){
        bowl = bowl + stone[i];
        stone[i] = 0;
      }else{
        stone[i]++;
        bowl--;
        if(bowl == 0 && stone[i] == p){ans = i; flg = false;}
      }
    }
    cout << ans << endl;
  }
}

C++: #include <stdio.h>
int main()
{
????int i=0, l,?? p, q, j=0;
????int d[50];
??
????while(1)
????????{
????????????for ( i = 0; i < 50; i++)
????????{
????????????d[i] = 0;
????????}???? 
????????????scanf("%d %d", &l, &p);
????????????if( l == 0 && p == 0 ) break;
????????????q = p;
????????????while(1)
????????{
????????????????????if ( i >= l ) i = 0;
????????????if ( p > 0 )
????????????????{
????????????????????d[i] += 1;
????????????????????p--;
????????????????????if ( d[i] == q && p == 0)
????????????????{
????????????????????break;
????????????????}?? 
????????????????}
????????????else if ( p == 0 )
????????????????{
????????????????????p = d[i];
????????????????????d[i] = 0;
????????????????}
????????????i++;
????????}
????????????printf("%d\n", i);
????????}
????return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<bitset>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main() {

    int n, p;
    while(cin >> n >> p && (n || p)) {
        int stones[n];
        int bowl = p;
        int now = 0;
        REP(i, n)   stones[i] = 0;
        
        while(true) {
            if (bowl > 1) {
                bowl -= 1;
                stones[now] += 1;
            } else if (bowl == 1) {
                bowl = 0;
                stones[now] += 1;
                if (stones[now] == p) break;
            } else {
                bowl = stones[now];
                stones[now] = 0;
            }
            now += 1;
            if(now == n)    now = 0;
        }
        cout << now << endl;
    }
     
    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 cnt = 0;
int pos = -1;
while(cnt!=1 || p){
pos = (pos+1)%n;
if(p){
if(!c[pos])cnt++;
c[pos]++;
p--;
}else{
if(!c[pos])
p = c[pos];
c[pos] = 0;
}
pos = (pos+1)%n;
}
cout << pos << end;;
}
}