题目链接:uva 616 - Coconuts, Revisited
题目大意:题目背景和uva 10726是一样的,只是这道题目是给出n,表示椰子的个数,并且猴子的个数为1,问说是否能找到满足的人数,并且要求人数尽量大。
解题思路:枚举人数,然后根据uva 10726推出的公式去求出最后剩下的椰子是否满足平分等判断。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll s;
bool judge () {
for (ll i = 12; i > 1; i--) {
ll b = i - 1;
ll t = (ll)pow(i, i);
if ((s + b) % t)
continue;
ll k = (s + b) / t;
ll p = (ll)pow(b, i);
ll q = k * p - b;
if (q % i)
continue;
printf("%lld people and 1 monkey\n", i);
return false;
}
return true;
}
int main () {
while (scanf("%lld", &s) == 1 && s != -1) {
printf("%lld coconuts, ", s);
if (judge ())
printf("no solution\n");
}
return 0;
}