In Love with Primes

Little Arjit is in love with Deepa. They have always thought of themselves as the ideal couple - the best, possible match they could've managed. (No kidding!) And like every other couple, they promised each other not to fight after every other fight. But, when has that happened before?

But, this is a different couple - this is a programming couple - and they argue on weird things, like Fibonacci numbers, prime numbers, Sterling numbers, and what not!

Their recent fight might seem silly to a lot of people, but it is a matter of serious concern for both of them. They have bought a cake, and they weighed it in milligrams - the weight of the cake is always even and now they wish to divide the cake between them in some way, that both of them are satisfied.

Arjit challenges Deepa that if she can divide the weight of the cake as the sum of two prime numbers between them, she can have the entire cake - and if she fails to do so, he'll get the cake.

The argument is getting more, and more heated now - please help them sort out their stupid arguments or an easier way would be to help them figure out who is going to have the cake.

Example:

Input:  n = 4
Output: Deepa

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;
    int flag = 0;
    for (int i = 2i < ni++)
    {
        if (isprime(i) && isprime(n - i))
        {
            flag = 1;
            break;
        }
    }
    if (flag == 0)
        cout << "Arjit\n";
    else
        cout << "Deepa\n";

    return 0;
}


No comments:

Post a Comment