<p>Given a non-negative integer <code>c</code>, decide whether there&#39;re two integers <code>a</code> and <code>b</code> such that <code>a<sup>2</sup> + b<sup>2</sup> = c</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> c = 5
<strong>Output:</strong> true
<strong>Explanation:</strong> 1 * 1 + 2 * 2 = 5
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> c = 3
<strong>Output:</strong> false
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>0 &lt;= c &lt;= 2<sup>31</sup> - 1</code></li>
</ul>

class Solution {
public:
    bool judgeSquareSum(int c) 
    {
        int k =pow(c,0.5);

        vector<long long int>a(k+2);

        for(int i=0;i<k+2;i++)
        {
            a[i]=i;
        }
       int p=0;
        int q=k+1;



        while(p<q)
        {
            if(pow(a[p],2)+pow(a[q],2)>c && 2*pow(a[q],2)>c)
            {
                q--;
            }

            else if (pow(a[p],2)+pow(a[q],2)<c  )
            {
                p++;
            }
            else if(pow(a[p],2)+pow(a[q],2)==c || 2*pow(a[p],2)==c ||2*pow(a[q],2)==c)
            {
                return true;
            }
        }

        if(c%2==0)
        {
            int a=c/2;
            for(int i=0;i<k+2;i++)
        {
            if(pow(i,2)==a)
            {
                return true;
            }
        }
        }

        return false;
    }
};
16700