I'm studying for a test and appreciate your help. How to calculate the running time (T(n)) of the following segment (written in Pascal):

```
k := 0;
m := n;
while m <= n do
begin
k := k + 1;
m := k * k;
end;
for i := 1 to k do
for j := i to k do
begin
s := s + m;
m := m - 1;
end;
```