for example, the following code takes O(n log n) times, because the running time of the while loop isn't constant, it depends on the value of a,
void regular(int R[], int n) {
int i = 0;
for(int a = 1; i < n; a++) {
int b = a;
while(b != 1) {
if (b % 2 == 0)
b = b / 2;
if (b % 3 == 0)
b = b / 3;
if (b % 5 == 0)
b = b / 5;
else break;
}
if (b == 1) {
R[i] == a;
i = i + 1;
}
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net