What is the sum of this
$$ \{n,n-1,...,3,2,1\}, ...... \{5,4,3,2,1\}, \{4,3,2,1\}, \{3,2,1\}, \{2,1\}, \{1\} $$
I am learning Data Structures and Algorithms now, I want to calculate the time-complexity of a nested loop. I suspect there is term and formula for this pattern.
static int count = 0;
//time complexity of this nested loop
public static void run(int n) {
for (int i = 1; i * i < n; i++) {
for (int j = i; j * j < n; j++) {
for (int k = j; k * k < n; k++) {
System.out.println(++count);
}
}
}
}
public static void cal(int n) {
int total = 0;
int temp = (int) Math.pow(n, 0.5);
for (int i = temp; i > 0; i--) {
total += i * (i + 1) / 2;
}
System.out.println(total);
}
public static void main(String[] args) {
run(12345);
cal(12345);
}