View Code of Problem 787

#include <stdio.h>
#include <string.h>

int fun(int m, int n) {
	if (m == 0) {
		return 1;
	}
	if (n == 0) {
		return 0;
	}
	if (m < n) {
		return fun(m, m);
	}
	else {
		return fun(m, n - 1) + fun(m - n, n);
	}
}

int main() {
	int t;
	int m, n;
	scanf("%d", &t);
	while (t--) {
		scanf("%d %d", &m, &n);
		printf("%d\n", fun(m, n));
	}
}

Double click to view unformatted code.


Back to problem 787