For example:
#include <iostream>
using namespace std;
int main() {
int n, s = 0, i, j, k;
cin >> n;
for (i = 1; i <= n * n; i++) {
for (j = 1; j <= i / 2; j++) {
s += i + j;
}
k = 1;
while (k < j) {
s += k;
k += 2;
}
}
cout << s << endl;
return 0;
}
How do I approach this?
The outer loop runs from 1 to n^2
The inner loop runs from 1 to i/2
The while loop runs while k is less than j
So, the time complexity should be larger than O(n^2), but this is where I get stuck. Any help would be appreciated
New contributor
Leon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.