We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c15b453 commit f6d5f3fCopy full SHA for f6d5f3f
USTC-ACM-Prob1018.cpp
@@ -0,0 +1,33 @@
1
+#include<iostream>
2
+
3
+using namespace std;
4
5
+bool check(long coconut,long people) {
6
+ long i;
7
+ for(i=0;i<people;i++) {
8
+ coconut--;
9
+ if(coconut%people!=0||coconut<0) return false;
10
+ coconut=coconut/people*(people-1);
11
+ }
12
+ if(coconut%people!=0) return false;
13
+ return true;
14
+}
15
16
17
+int main() {
18
+ long m,n;
19
+ cin>>n;
20
21
+ while(n>=0) {
22
+ cout<<n<<" coconuts, ";
23
+ for(m=10;m>=2;m--) {
24
+ if(check(n,m)) {
25
+ cout<<m<<" people and 1 monkey"<<endl;
26
+ break;
27
28
29
+ if(m==1) cout<<"no solution"<<endl;
30
31
32
+ return 0;
33
0 commit comments