The complexity of my algorithm is O(sqrt(n)) but still i am getting TLE ... dont know why...i there any better than that or should i use...some memoization
here is the q:
spoj.pl/problems/DIVSUM2/
#include<stdio.h>
#include<math.h>
#include<string.h>
void compute(long long k)
{
long long sum=0;long long x=0;
long long i;long long rt=sqrt(k);
if(k==1){printf("%d\n",0); return;}
for(i=1;i<=rt;i++)
{
if(k % i ==0)
{
sum+=i;
x=k/i;
if((x!=i)&&(x<=k/2))
sum+=x;
}
}
printf("%lld\n",sum);
}
int main()
{
long long N;int tc;
scanf("%d",&tc);
while(tc--){
scanf("%lld",&N);
compute(N);
}
return 0;
}