What will be the time complexity of the following function? is it $O(n^3)$ or $O(n^4)$?
i am getting $O(n^3)$ in the first for loop, it will undergo $n$ times. in the second for loop, for every nth element it will go $n^2$ times, therefore the total complexity till here is $O(n^3)$ now, the if statement will only hold true value only for n out of $n^2$ values, and for every $n$ values the $k$- for loop will go till $n^2$ elements and hence the complexity is $O(n^3)$. I have taken few values of $n$: for $n=3$ ,$c=25$
for $n=10$, $c=1705$
for $n=50$, $c=834275$
for(i=1;i<=n;++i)
for(j=1;j<=(i*i);++j)
if((j%i)==0)
for(k=1;k<=j;++k)
c=c+1;