#include <iostream>
#include <cmath>
using namespace std;
int main(){
cin.sync_with_stdio(0);
int n;
cin>>n;
while(n>=0){
int i=sqrt(n)+1,j,sum,flag=0;
for(;i>1;i--){
j=0,sum=n;
for(;j<i;j++){
// cout<<sum<<' ';
if(sum%i!=1)
break;
sum-=1;
sum-=sum/i;
}
// cout<<endl;
if(j==i&&sum%i==0){
flag=1;
break;
}
}
cout<<n<<" coconuts, ";
if(flag)
cout<<i<<" people and 1 monkey"<<endl;
else
cout<<"no solution"<<endl;
cin>>n;
}
}
#include <cmath>
using namespace std;
int main(){
cin.sync_with_stdio(0);
int n;
cin>>n;
while(n>=0){
int i=sqrt(n)+1,j,sum,flag=0;
for(;i>1;i--){
j=0,sum=n;
for(;j<i;j++){
// cout<<sum<<' ';
if(sum%i!=1)
break;
sum-=1;
sum-=sum/i;
}
// cout<<endl;
if(j==i&&sum%i==0){
flag=1;
break;
}
}
cout<<n<<" coconuts, ";
if(flag)
cout<<i<<" people and 1 monkey"<<endl;
else
cout<<"no solution"<<endl;
cin>>n;
}
}
Comments
Post a Comment