Friday 25 August 2017

Sherlock and Divisors hacker Rank solution in c



#include <stdio.h>
#include <math.h>
int main()
{
               int n,i,t,c;
               scanf("%d",&t);
               while(t--)
               {
                              c=0;
                              scanf("%d",&n);
                              for(i=1;i<=sqrt(n);i++)
                              {
                                             if(n%i == 0)    //i is divisor of n
                                             {
                                                            if(i%2 == 0)   //even divisor
                                                                           c++;
                                                            if((n/i)%2 == 0 && (n/i)!=i)   //if i is divisor of n then n/i is also divisor of n
                                                                           c++;
                                             }
                              }
                              printf("%d\n",c);
               }             
              
}

No comments:

Post a Comment