sum = 0;
for (i = 1; i <= n; i++) { //#1
for (j = 1; j <= i * i; j++) { //#2
if (j % i == 0) { //#3
for (k = 1; k <= j; k++) { //#4
sum++;
}
}
}
}
以上让我感到困惑
Suppose #1 runs for N times
#2 runs for N^2 times
#3 runs for N/c since for N inputs N/c could be true conditions
#4 runs for N times
因此,大致我可以看 O(N^5) 。我不确定。请帮助澄清。
编辑我想知道if(j%i==0)
. 由于它N^2
从其父循环中获取输入,因此它可能正在(N^2)/c
执行执行而不是N/c