16
I have written this block of code but it is consuming lots of time to calculate... Can you help me finding out an efficient way to do it?
int tag;
int* factors(int n)
{
int a[1000000];
for(int i=1;i<=n/2;i++)
if(n%i==0)
a[++tag]=i;
a[++tag]=n;
return(a);
}
This brute force method is very hefty in terms of complexity... Is there any better feasible solution to this problem?