Friday, December 1, 2017

DevSkill - Factorially Even or Odd Problem Solution

https://www.devskill.com/CodingProblems/ViewProblem/354


// Nayeem Shahriar Joy , Applied Physics & Electronic Engineering , University of Rajshahi.

#include<bits/stdc++.h>

using namespace std;

unsigned long long trailingzeroesfinding(unsigned long long n)

{

    unsigned long long  count=0;

       for(int i=5;n/i>=1;i=i*5)

       {

           count=count+(n/i);

       }

       return count;

}


int main()

{
   int t;
   cin>>t;
   unsigned long long n;
   while(t--)
   {
       cin>>n;
       unsigned long long  trailing=trailingzeroesfinding(n);
       int joy =0;
       if(trailing==1)
       {
           joy=1;
       }
       else{
       for(unsigned long long i=1;pow(2,i)<=trailing;i++)

       {
           if(pow(2,i)==trailing)

           {
               joy=1;
               break;

           }
       }
       }
     if(joy)
     {
         cout<<"Even"<<endl;
     }
     else
     {
         cout<<"Odd"<<endl;
     }
   }
   return 0;
}

No comments:

Post a Comment