#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll>divisors;
void div(ll n)
{
divisors.clear();
ll i,j,k,l,m;
for(i=2;i<=sqrt(n)+1;i++)
{
if(n%i==0)
{
divisors.push_back(i);
j=n/i;
if(i!=j)
{
divisors.push_back(j);
}
}
}
sort(divisors.begin(),divisors.end());
}
int main()
{
ll i,j,k,l,m,n;
while(cin>>n)
{
if(n<0)
{
break;
}
else
{
cout<<n<<" coconuts, ";
div(n-1);
ll num;
//cout<<num<<endl;
bool flag=0;
if(divisors.size()==0)
{
cout<<"no solution"<<endl;
continue;
}
for(i=divisors.size()-1;i>=0;i--)
{
ll rem=0;
ll num=n;
//cout<<divisors[i]<<endl;
if(flag)
break;
for(j=0;j<divisors[i];j++)
{
num-=rem;
//cout<<num<<" "<<rem<<" ";
ll r=num%divisors[i];
if(num<0)
{
flag=0;
break;
}
//cout<<r<<" ";
if(r!=1)
{
flag=0;
break;
}
num--;
//cout<<num<<" ";
if(num%divisors[i]!=0)
{
flag=0;
break;
}
else
{
rem=num/divisors[i];
}
}
//cout<<num<<" "<<rem<<" "<<j<<endl;
rem=num/divisors[i];
if(rem%divisors[i]==0&&j==divisors[i])
{
flag=1;
cout<<divisors[i]<<" people and 1 monkey"<<endl;
}
else
{
flag=0;
}
}
if(!flag)
cout<<"no solution"<<endl;
}
}
return 0;
}
using namespace std;
typedef long long ll;
vector<ll>divisors;
void div(ll n)
{
divisors.clear();
ll i,j,k,l,m;
for(i=2;i<=sqrt(n)+1;i++)
{
if(n%i==0)
{
divisors.push_back(i);
j=n/i;
if(i!=j)
{
divisors.push_back(j);
}
}
}
sort(divisors.begin(),divisors.end());
}
int main()
{
ll i,j,k,l,m,n;
while(cin>>n)
{
if(n<0)
{
break;
}
else
{
cout<<n<<" coconuts, ";
div(n-1);
ll num;
//cout<<num<<endl;
bool flag=0;
if(divisors.size()==0)
{
cout<<"no solution"<<endl;
continue;
}
for(i=divisors.size()-1;i>=0;i--)
{
ll rem=0;
ll num=n;
//cout<<divisors[i]<<endl;
if(flag)
break;
for(j=0;j<divisors[i];j++)
{
num-=rem;
//cout<<num<<" "<<rem<<" ";
ll r=num%divisors[i];
if(num<0)
{
flag=0;
break;
}
//cout<<r<<" ";
if(r!=1)
{
flag=0;
break;
}
num--;
//cout<<num<<" ";
if(num%divisors[i]!=0)
{
flag=0;
break;
}
else
{
rem=num/divisors[i];
}
}
//cout<<num<<" "<<rem<<" "<<j<<endl;
rem=num/divisors[i];
if(rem%divisors[i]==0&&j==divisors[i])
{
flag=1;
cout<<divisors[i]<<" people and 1 monkey"<<endl;
}
else
{
flag=0;
}
}
if(!flag)
cout<<"no solution"<<endl;
}
}
return 0;
}
No comments:
Post a Comment