HDU : Friend


// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <sstream>
#include <set>
#include <math.h>
#define pi acos(-1.0)
#define N 1000000
using namespace std;


int main ()
{
    set <long long> frndNumber;
    frndNumber.insert (-1);
    frndNumber.insert (1);
    frndNumber.insert (2);
    set <long long>::iterator it;
    set <long long>::iterator it2;

    for ( it = frndNumber.begin (); it != frndNumber.end (); it++ ) {
        for ( it2 = it; it2 != frndNumber.begin (); it2-- ) {
            long long next = (*it * *it2) + *it + *it2;
            if ( next > 1073741824 )
                break;
            frndNumber.insert (next);
        }
    }

    //cout << frndNumber.size () << endl;

    int num;

    while ( scanf ("%d", &num) != EOF ) {
        bool found = false;

        for ( it = frndNumber.begin (); it != frndNumber.end (); it++ ) {
            if ( *it == num )
                found = true;
        }

        if ( found )
            printf ("YES!\n");
        else
            printf ("NO!\n");
    }

    return 0;
}

// @END_OF_SOURCE_CODE
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s