Posted: Sat Apr 22, 2006 5:16 am
For IRA
if see my snippet code maybe you can understand why the time complexity is O(sqrt(n))
don't use my snippet code to be part of your program,
my snippet code is wrong because I don't write the last operation that
consume O(1) before return out2.
Hope it help you

Code: Select all
#define I long long
I CSOD(I n)
{
I i,out2=0,j=sqrt(n);
for(i=2;i<=j;i++) out2 += (n/i)*i; // O(sqrt(n))
for(i--;j>=1;j--) { out2 += (j*sum(i+1,n/j)); i=(n/j); } // O(sqrt(n))
// last operation before return only take O(1)
return out2;
}
don't use my snippet code to be part of your program,
my snippet code is wrong because I don't write the last operation that
consume O(1) before return out2.
Hope it help you
