hi see the logic all the factors of a number are evenly distributed about
it's square root
for e.g 100
1 X 100
2 X 50
4 X 25
5 X 20
10 X 10
AFTER THIS THE PAIRS REPEATE THEMSELVES BUT IN OPPOSITE ORDER
20 X 5
25 X 4
50 X 2
100  X 1
SO IF YOU MAKE YOUR LOOP GO TO SQRT(N) AND IF YOU FIND A FACTOR OF THAT
NUMBER ANOTHER FACTOR CAN BE FOUND BY DIVING THAT FACTOR WITH THE NUMBER....
FOR  E.G. IF YOU FIND 4 THEN 25 IS FOUND BY 100/4


#include<stdio.h>
#include<math.h>
main()
{
      long long int  n,i,t,d,k,l;
     // long int a,b;
      scanf("%lld",&t);
      while(t)
      {
              d=0;
              scanf("%lld",&n);
              k=sqrt(n);
              for(i=1;i<=k;i++)
              {

                               if((n%i)==0)
                               {
                                           d=d+i;
                                           l=n/i;
                                           if(i!=l)
                                           d=d+l;
                               }
              }
              printf("%lld\n",d-n);
              t--;
      }
      return (0);
}




-- 
*UTKARSH SRIVASTAV
CSE-3
B-Tech 3rd Year
@MNNIT ALLAHABAD*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to