Gone bananas

You are required to distribute bananas among some people according to the following conditions:

  • You can select the number of people that receive bananas.
  • Each person should get more than one banana.
  • One person cannot receive all the bananas.
  • All the N bananas must be distributed.
  • Each person can only receive an integral number of bananas.

Write a program to determine whether the bananas can be distributed among the people.

Example:

Input:  n = 4
Output: Yes

Approach

C++

#include <bits/stdc++.h>
using namespace std;

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2i <= sqrt(n); i++)
        if (n % i == 0)
            return false;
    return true;
}
int main()
{

    int n = 4;

    if (n <= 2)
        cout << "No\n";
    else if (n % 2 == 0)
        cout << "Yes\n";
    else if (isprime(n))
        cout << "No\n";
    else
        cout << "Yes\n";

    return 0;
}


No comments:

Post a Comment