Hacker Rank Lucky Numbers

/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.

*/

#include<bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back

typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;

const int mod = 1000007;
const int high = 100;

// modified needed.................................
LL bigmod(LL a , LL b , LL c)
{
    if(!b) return 1;

    if(!(b & 1))
    {
        LL x = bigmod(a , b / 2 , c)%c;
        return ((x % c) * (x % c ))%c;
    }

    else
        return ((a%c) * (bigmod(a , b-1, c) %c ))%c;
}
//......................................................

LL modInverse(LL a, LL mod){return bigmod(a , mod-2 , mod);}

class sample
{
public:
    void ek(int x)
    {
        cout << x << "\n";
    }

    void dui(int x , int y)
    {
        cout << x << " " << y << "\n";
    }

    void tin(int x , int y , int z)
    {
        cout <<  x << " " << y << " " << z << "\n";
    }
};

int main()
{
    fast;
    sample samobj;
    int q;
    LL n , i;
    cin >> q;
    while(q--)
    {
        cin >> n;

        if(n % 4 == 0 or n % 7 == 0) outn("Yes");
        else
        {
            LL qrt = sqrt(n);

            bool f=false;

            for(i=1; i<n; i++)
            {
                LL def = n - (4 * i);

                if(def >= 7 and def % 7 == 0)
                {
                    outn("Yes");
                    f=true;
                    break;
                }
            }

            if(!f) outn("No");
        }
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number