Skip to content

Commit f6d5f3f

Browse files
committed
USTC-ACM-Prob1018
/** * Normal method. */
1 parent c15b453 commit f6d5f3f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

USTC-ACM-Prob1018.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
cin>>n;
31+
}
32+
return 0;
33+
}

0 commit comments

Comments
 (0)