Reduce checks in a for loop

This loop checks if the input can be achieved with the sum of 2 number raised on 2,but i want it to stop doing the same sums like 0^2+1^2 and 1^2+0^2.Something like when you do 0^2+1^2 and you also have to find all powers of 1^2 too,skip 0^2.Thanks in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    unsigned int input = 0, rootmax = 0;

    cout << "Input a number: ";
    cin >> input;
    cout << "-----------" << endl;

    rootmax = sqrt(input);

    for(unsigned int i = 0; i <= rootmax; i++)
        for(unsigned int j = 0; j <= rootmax; j++)
            if(pow(i, 2) + pow(j, 2) == input)
                cout << i << "^2 + " << j << "^2 = " << input << endl;

    return 0;
}
Use i as the start value of j: for(unsigned int j = i; j <= rootmax; j++)
Topic archived. No new replies allowed.