View Code of Problem 64

#include <iostream>
#include <string>
using namespace std;
int people (int n, int k, int l) {
	if (n <= 0 || 2 * k - k/2 > l) return k;
	return people(--n, 2 * k - k/2, l);
}
int main() {
	int n, k, l;
	while (1) {
		int ki;
		scanf("%d %d %d", &n, &k, &l);
		if (!n && !k && !l) break;
		cout << people (n-2, k , l) <<  endl; 
//		for (int i=1; i<n-1; ++i){
//			if (2 * k - k/2 > l) break;
//			k = 2 * k - k/2;
//			
//		}
//		cout << k << endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 64