Problem:
Problem H:
Finding the Top RPS Player
A company “ACM Foods” is preparing for opening its chain shop in a certain area, but another company “ICPC
Pizza” is also planning to set up its branch shop in the same area. In general, two competitive shops gain less
incomes if they are located so close to each other. Thus, if both “ACM Foods” and “ICPC Pizza” went on
opening, they would be damaged financially. So, they had a discussion on this matter and made the following
agreement: only one of them can branch its shop in the area. It is determined by Rock-Paper-Scissors (RPS)
which to branch the shop.
ACM Foods is facing financial difficulties and strongly desires to open their new shop in that area. The executives
have decided to make every effort for finding out a very strong RPS player. They believes that players who win
consecutive victories must be strong players. In order to find such a player for sure, they have decided their
simple strategy.
In this strategy, many players play games of RPS repeatedly, but the games are only played between players with
the same number of consecutive wins. At the beginning, all the players have no wins, so any pair of players
can play a game. The games can be played by an arbitrary number of pairs simultaneously. Let us call a set of
simultaneous games as a
turn
. After the first turn, some players will have one win, and the other players will
remain with no wins. In the second turn, some games will be played among players with one win, and some
other games among players with no wins. For the former games, the winners will have two
consecutive
wins,
and the losers will lose their first wins and have no consecutive wins. For the latter games, the winners will have
one win, and the losers will remain with no wins. Therefore, after the second turn, the players will be divided
into three groups: players with two consecutive wins, players with one win, and players with no wins. Again,
in the third turn, games will be played among players with two wins, among with one win, and among with no
wins. The following turns will be conducted so forth. After a sufficient number of turns, there should be a player
with the desired number of consecutive wins.
The strategy looks crazy? Oh well, maybe they are confused because of their financial difficulties.
Of course, this strategy requires an enormous amount of plays. The executives asked you, as an employee of
ACM Foods, to estimate how long the strategy takes. Your task is to write a program to count the minimum
number of turns required to find a player with
M
consecutive wins among
N
players.
Input
The input consists of multiple test cases. Each test case consists of two integers
N
(2 ≤
N
≤ 20) and
M
(1 ≤
M
<
N
) in one line.
The input is terminated by the line containing two zeroes.
Output
For each test case, your program must output the case number followed by one integer which indicates the
minimum number of turns required to find a person with
M
consecutive wins.
Sample Inpu
...(truncated)

Submitted solutions:

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN=30;
int a[MAXN], b[MAXN];
int main(){
    int n, m, cs=1;
    while(cin>>n>>m&&n+m){
        int cnt=0;
        memset(a,0,sizeof a);
        a[0]=n;
        while(!a[m]){
            b[0]=a[0]%2;
            for(int i=0; i<=m; i++){
                if(i) b[i]=a[i]%2+a[i-1]/2;
                b[0]+=a[i]/2;
            }
            swap(a,b);
            cnt++;
        }
        printf("Case %d: %d\n",cs++,cnt);
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3480
final_rank: 7

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

int main() {
    for (int tc = 1; ; tc++) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<int> now(m + 1, 0), to(m + 1, 0);
        now[0] = n;
        int ans = 0;
        while (true) {
            ++ans;
            fill(to.begin(), to.end(), 0);
            for (int i = 0; i <= m - 1; ++i) {
                int prs = now[i] / 2;
                int rem = now[i] % 2;
                to[i + 1] += prs;
                to[i] += rem;
                to[0] += prs;
            }
            if (to[m] > 0) break;
            now = to;
        }
        cout << "Case " << tc << ": " << ans << "\n";
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3444
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int count(const int n, const int m) {
	std::vector<std::vector<int>> count(2, std::vector<int>(m + 1, 0));
	count[0][0] = n;
	int result = 0;
	while (count[result % 2][m] == 0) {
		for (auto& c : count[(result + 1) % 2]) c = 0;
		for (auto i = 0; i < m; ++i) {
			count[(result + 1) % 2][i + 1] += count[result % 2][i] / 2;
			count[(result + 1) % 2][0] += count[result % 2][i] / 2;
			count[(result + 1) % 2][i] += count[result % 2][i] % 2;
		}
		++result;
	}
	return result;
}
int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	std::vector<std::vector<int>> result(21, std::vector<int>(21));
	for (auto i = 2; i <= 20; ++i) {
		for (auto j = 1; j < i; ++j) {
			result[i][j] = count(i, j);
		}
	}
	for (auto t = 1;true; ++t) {
		int n, m; std::cin >> n >> m; if (n == 0 && m == 0) break;
		std::cout << "Case " << t << ": " << result[n][m] << '\n';
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3144
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 20;
int ans[N+1][N+1];

int main(){
    for(int i=2; i<=N; ++i){
        vector<bool> vis(i+1);
        vector<int> a(i+1);
        a[0] = i;
        vis[0] = true;

        int t = 0;
        while(!vis[i-1]){
            ++t;

            vector<int> na(i+1);
            rep(j,i){
                na[j+1] += a[j]/2;
                na[0] += a[j]/2;
                na[j] += a[j]%2;

                if(!vis[j] && na[j]>0){
                    vis[j] = true;
                    ans[i][j] = t;
                }
            }

            a = na;
        }
    }

    int C = 1;
    int n,m;
    while(scanf(" %d %d", &n, &m),n) printf("Case %d: %d\n", C++, ans[n][m]);
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3224
final_rank: 5

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;



 int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const long long  int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}

#define MAX_MOD_N 1024000

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init(const int amax = MAX_MOD_N) {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < amax - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}

vector<pair<int, int>>get_connect(int N, int x, int y) {
	vector<pair<int,int>>anss;
	{
		int ax=x-1;
		int ay=y;
		anss.emplace_back(ax,ay);
	}
	{
		int ax=x+1;
		int ay=y;
		anss.emplace_back(ax, ay);

	}

	//lu
	{
		int ax,ay;
		if (y < N) {
			ax=x-1;
			ay=y-1;
		}
		else {
			ax=x;
			ay=y-1;
		}
		anss.emplace_back(ax, ay);

	}

	//ru
	{
		int ax,ay;
		if (y < N) {
			ax=x;
			ay=y-1;
		}
		else {
			ax=x+1;
			ay=y-1;
		}
		anss.emplace_back(ax, ay);

	}

	//ld
	{
		int ax,ay;
		if (y < N - 1) {
			ax=x;
			ay=y+1;
		}
		else {
			ax=x-1;
			ay=y+1;
		}
		anss.emplace_back(ax, ay);

	}
	//rd
	{
		int ax,ay;
		if (y < N - 1) {
			ax=x+1;
			ay=y+1;
		}
		else {
			ax=x;
			ay=y+1;
		}
		anss.emplace_back(ax, ay);

	}
	vector<pair<int,int>>real_anss;
	for (auto ans : anss) {
		int ax(ans.first);
		int ay(ans.second);
		bool ok=true;
		if(ay<0||ay>=2*N-1)ok=false;
		if (ay < N) {
			if(ax<0||ax>=N+ay)ok=false;
		}
		else {
			if (ax < 0 || ax>=3*N-ay-2)ok=false;
		}
		if(ok)real_anss.emplace_back(ans);
	}
	return real_anss;
}


template<typename T>
vector<vector<T>> keisann(const vector<vector<T>>l, const vector<vector<T>>r) {
	vector<vector<T>>ans(l.size(), vector<T>(r[0].size()));
	assert(l[0].size() == r.size());
	for (unsigned int h = 0; h < l.size(); ++h) {
		for (unsigned int i = 0; i < r.size(); ++i) {
			for (unsigned int w = 0; w < r[0].size(); ++w) {

				ans[h][w] += l[h][i] * r[i][w];
			}
		}
	}
	return ans;
}

template<typename T>
vector<vector<T>>powgyou(vector<vector<T>>a, const long long int n) {
	assert(a.size() == a[0].size());
	if (!n) {
		vector<vector<T>>e(a.size(), vector<T>(a[0].size()));
		for (unsigned int i = 0; i < a.size(); ++i) {
			e[i][i] = 1;
		}
		return e;
	}
	if (n == 1)return a;
	else {
		vector<vector<T>>ans(a.size(), vector<T>(a[0].size(), 0));
		ans = powgyou(a, n / 2);
		ans = keisann(ans, ans);
		if (n % 2) {
			ans = keisann(ans, a);
		}
		return ans;
	}
}


int main() {
	int case_id=0;
	while (true) {
		case_id++;
		int N,M;cin>>N>>M;
		if(!N)break;
		vector<int>nums(M+1);
		nums[0]=N;
		int ans=0;
		while (true) {
			ans++;
			vector<int>next_nums(M+1);
			for (int i = 0; i < M; ++i) {
				next_nums[i+1]+=nums[i]/2;
				next_nums[0]+=(nums[i])/2;
				next_nums[i]+=nums[i]%2;
			}
			nums=next_nums;
			if(nums[M])break;
		}
		cout<<"Case "<<case_id<<": "<<ans<<endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 11152
final_rank: 19

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N,M;
int test_case = 1;

void func(){

	int table[M+1],next[M+1];

	table[0] = N;
	for(int i = 1; i <= M; i++)table[i] = 0;

	int count = 0;

	while(true){
		for(int i = 0; i <= M; i++)next[i] = 0;

		count++;

		for(int i = 0; i < M; i++){
			if(table[i] >= 2){
				next[i+1] += table[i]/2;
				next[0] += table[i]/2;
				next[i] += table[i]%2;
			}else{
				next[i] += table[i];
			}
		}

		for(int i = 0; i <= M; i++)table[i] = next[i];

		if(table[M] > 0)break;
	}

	printf("Case %d: %d\n",test_case++,count);
}

int main(){

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3084
final_rank: 3

code_snippet: #include <vector>
#include <iostream>
using namespace std;
int n, m, c;
int main() {
	while (cin >> n >> m, n | m) {
		vector<int> v(m + 1); v[0] = n;
		int ret = 0;
		while (v[m] == 0) {
			vector<int> w(m + 1);
			for (int i = 0; i < m; i++) {
				w[i + 1] += v[i] / 2;
				w[0] += v[i] / 2;
				w[i] += v[i] % 2;
			}
			v = w; ret++;
		}
		cout << "Case " << ++c << ": " << ret << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3144
final_rank: 13

code_snippet: #include<iostream>
using namespace std;
int x[25],y[25],n,m,p,c;
int main(){
	while(true){
		cin>>n>>m;if(n==0)break;
		for(int i=0;i<25;i++)x[i]=0;
		x[0]=n;p++;c=0;
		while(x[m]<1){
			c++;for(int i=0;i<25;i++)y[i]=0;
			for(int i=0;i<m;i++){
				y[i]+=x[i]%2;
				y[0]+=x[i]/2;
				y[i+1]+=x[i]/2;
			}
			for(int i=0;i<=m;i++){x[i]=y[i];}
		}
		cout<<"Case "<<p<<": "<<c<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1164
final_rank: 9

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m;
	int cnt=1;
	while(cin>>n>>m,n+m){
		vi in(m+1);
		in[0]=n;
		int out=1;
		while(1){
			vi tmp=in;
			int c=0;
			for(int i=m;i>=1;i--){
				tmp[i]+=tmp[i-1]/2;
				c+=tmp[i-1]/2;
				tmp[i-1]-=tmp[i-1]/2*2;
			}
			tmp[0]+=c;
			in=tmp;
			if(in[m])break;
			out++;
		}
		cout<<"Case "<<cnt<<": "<<out<<endl;;
		cnt++;
	}
}
accuracy: 1
time_ms: 30
memory_kb: 1216
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m,T=1;
  while(cin >> n >> m && n) {
    int d[m+1];
    mem(d);
    d[0]=n;
    int t=0;
    while(!d[m]) {
      int sum=0;
      rrep(i,m) {
        int x=d[i]/2;
        d[i+1]+=x;
        d[i]-=x*2;
        sum+=x;
      }
      d[0]+=sum;
      t++;
    }
    cout << "Case " << T++ << ": " << t << endl;
  }
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1204
final_rank: 1

code_snippet: #include <iostream>
#include <cstring>
#include <vector>
 
using namespace std;

#define MAX 20

int main(){
    int N,M,T = 1;
 
    while(cin >> N >> M , N | M){
	int cnt = 0;
	vector<int> res(M+1,0);
	res[0] = N;
 
	while(true){
	    vector<int> tmp(M+1,0);
 
	    if(res[M]) break;  
	    cnt++;      
 
	    for(int i = 0 ; i < M ; i++){
		if(res[i] >= 2){
		    tmp[i+1] += res[i] / 2;
		    tmp[0] += res[i] / 2;
		    if(res[i] % 2) tmp[i]++;
		}
		else
		    tmp[i] += res[i];
	    }
 
	    res = tmp;
	}
	cout << "Case " << T++ << ": ";
	cout << cnt << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3080
final_rank: 2

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
int now[30];
int to[30];
int main(){
	int a,b;
	int T=0;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<30;i++)now[i]=0;
		now[0]=a;
		int t=0;
		while(1){
			t++;
			for(int i=0;i<a;i++){
				to[i]=0;
			}
			for(int i=0;i<a;i++){
				to[i+1]+=now[i]/2;
				to[i]+=now[i]%2;
				to[0]+=now[i]/2;
			}
			for(int i=0;i<a;i++)now[i]=to[i];
			if(to[b])break;
		}
		printf("Case %d: %d\n",++T,t);
	}
}
accuracy: 1
time_ms: 30
memory_kb: 1028
final_rank: 14

code_snippet: #include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <algorithm>
#include <cassert>

using namespace std;

const int N = 30;
int n, m;
int a[N];
int b[N];

void solve()
{
	memset(a, 0, sizeof a);
	a[0] = n;
	int c;
	for(c = 0; a[m] == 0; ++ c) {
		memset(b, 0, sizeof b);
		for(int i = 0; i <= m; ++ i) {
			b[0] += a[i] / 2;
			b[i + 1] += a[i] / 2;
			b[i] += a[i] & 1;
		}
		for(int i = 0; i <= m; ++ i) {
			a[i] = b[i];
		}
	}
	cout << c << endl;
}

int main()
{
	int test = 0;
	for( ; cin >> n >> m && (n || m); ) {
		printf("Case %d: ", ++ test);
		solve();
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1188
final_rank: 11

code_snippet: #include <iostream>
using namespace std;


int main(){
    int win[20], N, M, a, c;
    cin >> N >> M;
    a = 1;
    while( M + N > 0 ){
        for(int x = 1; x < 20; x++){
            win[x] = 0;
        }
        win[0] = N;
        c = 0;
        while( !win[M] ){
            int loser = 0;
            for(int x = M-1; x >= 0; x--){
                win[x+1] += win[x]/2;
                loser += win[x]/2;
                win[x] %= 2;
            }
            win[0] += loser;
            c++;
        }
        cout << "Case " << a << ": " << c << endl;
        cin >> N >> M;
        a++;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1160
final_rank: 8

code_snippet: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <complex>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <iomanip>

using namespace std;


#define INF (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)

// rep
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// useful
#define FST first
#define SND second

#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss; oss << a; return oss.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

// !!! set SSIEVVE_MAX_L number !!!
#define SSIEVE_MAX_L (1000001)
#define SSIEVE_MAX_SQRT_B ((int)sqrt(INT_MAX)+1)
 
bool is_prime[SSIEVE_MAX_L];
vector<bool> is_prime_small(SSIEVE_MAX_SQRT_B);
 
void segment_sieve(ll a, ll b) {
   
  for(int i=0; (ll)i*i < b; i++) is_prime_small[i] = true;
  for(int i=0; i < b-a; i++) is_prime[i] = true;
   
  if(a == 1) {
    is_prime[0] = false;
  }
   
  for(int i=2; (ll)i*i<b; i++) {
    if(is_prime_small[i]) {
      for(int j=2*i; (ll)j*j<b; j+=i) is_prime_small[j] = false;
      for(ll j = max(2LL, (a+i-1)/i)*i; j<b; j+=i) is_prime[j-a] = false;
    }
  }
}

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

//////////////////////////////////////////////////////////////

int main() {
  
  int N, M;
  int tcase = 1;
  
  while(cin >> N >> M && (N|M)) {
    VI next(22), now(22);
    
    /*
    for(int i=0; i<N/2; i++) {
      next[0] = ++ now[0], next[1] = ++ now[1];
    }
    if(N % 2) next[0] = ++ now[0];
    */
    
    now[0] = N;
    
    int ans = 0;
    while(now[M] == 0) {
      fill(ALL(next), 0);
      for(int i=0; i<22; i++) {
	next[i+1] += now[i] / 2;
	next[0] += now[i] / 2;
	next[i] += now[i] % 2;
      }
      ans ++;
      
      /*
	for(int i=0; i<22; i++) now[i] = next[i];
      */

      now.swap(next);
    }
    
    cout << "Case " << tcase ++ << ": " << ans << endl;
    
  }
  
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1200
final_rank: 12

code_snippet: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <complex>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <iomanip>

using namespace std;


#define INF (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)

// rep
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// useful
#define FST first
#define SND second

#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss; oss << a; return oss.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

// !!! set SSIEVVE_MAX_L number !!!
#define SSIEVE_MAX_L (1000001)
#define SSIEVE_MAX_SQRT_B ((int)sqrt(INT_MAX)+1)
 
bool is_prime[SSIEVE_MAX_L];
vector<bool> is_prime_small(SSIEVE_MAX_SQRT_B);
 
void segment_sieve(ll a, ll b) {
   
  for(int i=0; (ll)i*i < b; i++) is_prime_small[i] = true;
  for(int i=0; i < b-a; i++) is_prime[i] = true;
   
  if(a == 1) {
    is_prime[0] = false;
  }
   
  for(int i=2; (ll)i*i<b; i++) {
    if(is_prime_small[i]) {
      for(int j=2*i; (ll)j*j<b; j+=i) is_prime_small[j] = false;
      for(ll j = max(2LL, (a+i-1)/i)*i; j<b; j+=i) is_prime[j-a] = false;
    }
  }
}

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

//////////////////////////////////////////////////////////////

int main() {
  
  int N, M;
  int tcase = 1;
  
  while(cin >> N >> M && (N|M)) {
    VI next(22), now(22);
    
    for(int i=0; i<N/2; i++) {
      next[0] = ++ now[0], next[1] = ++ now[1];
    }
    if(N % 2) next[0] = ++ now[0];
    
    int ans = 1;
    while(now[M] == 0) {
      fill(ALL(next), 0);
      for(int i=0; i<22; i++) {
	next[i+1] += now[i] / 2;
	next[0] += now[i] / 2;
	next[i] += now[i] % 2;
      }
      ans ++;
      
      for(int i=0; i<22; i++) now[i] = next[i];
    }
    
    cout << "Case " << tcase ++ << ": " << ans << endl;
    
  }
  
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1196
final_rank: 15

code_snippet: #include<iostream>
#include<vector>

using namespace std;

typedef pair<int,int> ii;
int N,M,CNT = 1;

int main(){
  while(cin >> N >> M,N|M){
    vector<ii> phase;    
    int turn=0;
    phase.push_back(ii(0,N));
    while(true){
      turn++;
      int zero = 0,tmp[M+1],mex = 0;
      for(int i=0;i<=M;i++)tmp[i] = 0;
      for(int i=0;i<phase.size();i++){
	int key = phase[i].first;
	int value = phase[i].second;
	if(value&1)value--,tmp[key]++;
	if(value / 2)mex = max(mex,key+1);
	tmp[key+1] += value / 2, tmp[0] += value / 2;
      }
      phase.clear();
      for(int i=0;i<=M;i++)if(tmp[i] != 0)phase.push_back(ii(i,tmp[i]));
      if(mex == M){
	cout << "Case " << CNT++ << ": " << turn << endl;
	break;
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 1200
final_rank: 20

code_snippet: #include <iostream>
#include <cstring>
#include <vector>
#define MAX 20

using namespace std;

int main(){
  int N,M,T = 1;

  while(cin >> N >> M , N | M){
    int cnt = 0;
    vector<int> res(M+1,0);
    res[0] = N;

    while(true){
      vector<int> tmp(M+1,0);

      if(res[M]) break;  
      cnt++;      

      for(int i = 0 ; i < M ; i++){
	if(res[i] >= 2){
	  tmp[i+1] += res[i] / 2;
	  tmp[0] += res[i] / 2;
	  if(res[i] % 2) tmp[i]++;
	}
	else
	  tmp[i] += res[i];
      }

      res = tmp;
    }

    cout << "Case " << T++ << ": ";
    cout << cnt << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1212
final_rank: 16

code_snippet: #include <iostream>
#include <cstring>
#include <vector>
#define MAX 20

using namespace std;

typedef long long ll;

int main(){
  int N,M,T = 1;

  while(cin >> N >> M , N | M){
    ll cnt = 0;
    vector<int> res(M+1,0);
    res[0] = N;

    while(true){
      vector<int> tmp(M+1,0);

      if(res[M]) break;  
      cnt++;      

      for(int i = 0 ; i < M ; i++){
	if(res[i] >= 2){
	  tmp[i+1] += res[i] / 2;
	  tmp[0] += res[i] / 2;
	  if(res[i] % 2) tmp[i]++;
	}
	else
	  tmp[i] += res[i];
      }

      res = tmp;
    }

    cout << "Case " << T++ << ": ";
    cout << cnt << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1212
final_rank: 16

code_snippet: #include <iostream>

using namespace std;

typedef long long ll;

int main(){
  int n,m;

  for(int I = 0 ;; I++){
    ll ans = 0;
    int res[21] = {0};    

    cin >> n >> m;

    if(n == 0 && m == 0) break;
    res[0] = n;    

    int tmp[n];

    while(true){
      fill(tmp,tmp+n,0);

      if(res[m]) break;
      ans++;

      for(int i = 0 ; i < n ; i++){
	if(res[i] >= 2){
	  tmp[i+1] += res[i] / 2;
	  tmp[0] += res[i] / 2;

	  if(res[i] % 2)
	    tmp[i]++;
	}
	else{
	  tmp[i] += res[i];
	}
      }
      
      for(int i = 0 ; i < n ; i++){
	res[i] = tmp[i];
      }
    }    

    cout << "Case " << I+1 << ": ";
    cout << ans << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1164
final_rank: 9