1,469 views
0 votes
0 votes

Given a non negative integer A,
following code tries to find all pair of integers (a, b) such that

  • a and b are positive integers
  • a <= b, and
  • a2 + b2 = A.
  • 0 <= A <= 100000

However, the code has a small bug. Correct the bug and submit the code.

vector<vector<int> > Solution::squareSum(int A) {
    vector<vector<int> > ans;
    for (int a = 0; a * a < A; a++) {
        for (int b = 0; b * b < A; b++) {
            if (a * a + b * b == A) {
                vector<int> newEntry;
                newEntry.push_back(a);
                newEntry.push_back(b);
                ans.push_back(newEntry);
            }
        }
    }
    return ans;
}

Please log in or register to answer this question.

Related questions

1 votes
1 votes
1 answer
1
Desert_Warrior asked May 15, 2016
2,587 views
main() { int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ); }