/* Author: ACb0y Date: 2010-8-25 Type: Water~~(force) ProblemId: hdu 1346 Coconuts, Revisited */ #include <iostream> using namespace std; int n; int get_ans() { int i, j; /* 从n开始递减枚举(n -> 1) */ for (i = n; i > 0; i--) { int total = n; //模拟处理过程 for (j = 0; j < i; j++) { if (total % i == 1) { total -= total / i + 1; } else { break; } } //如果模拟成功则返回结果,第一个符合要求的数就是最大的数。 if (j == i && total % i == 0) { return i; } } return 0; } int main() { #ifndef ONLINE_JUDGE freopen("1346.txt", "r", stdin); #endif while (cin >> n) { if (n == -1) { break; } else { int ans = get_ans(); if (ans == 0) { cout << n << " coconuts, no solution" << endl; } else { cout << n << " coconuts, " << ans << " people and 1 monkey" << endl; } } } return 0; }