HackerRank Sherlock and Divisors

// Accepted

#include<iostream>
#include<cstdio>
#include<cmath>

#define sf scanf
#define pf printf

using namespace std;

typedef long long LL;

LL div_two(LL num)
{
    LL cnt=1;

    for(LL i=2; i*i<=num; i++)
    {
        if(!(num % i))
        {
            if(!(i & 1))
            {
                cnt+=1;
            }

            LL nm = num / i;

            if(!(nm & 1))
            {
                if(nm != i)
                {
                    cnt+=1;
                }
            }
        }
    }

    return cnt;
}

int main()
{
    int t;
    sf("%d",&t);

    while(t--)
    {
        LL n;
        sf("%lld",&n);

        if(n&1)
        {
            pf("0\n");
        }
        else
        {
            pf("%lld\n",div_two(n));
        }
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number