bool fn(const float&c)
{//a^2+b^2=c
if (sqr(sqrt(c)) == c) //perfect square
{
float a=1; float b=c-1;
while(a<=b){
float a2=a*a;
float b2=b*b;
if (a2+b2==c) return true;
if (a*2+b2<c) { a+=1;}
else ( b-=1;}
}
}
return false;
}
Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652
On Thu, May 26, 2011 at 12:29 AM, ricky <[email protected]> wrote:
> can anyone help me out with this problem:
> https://www.spoj.pl/problems/TWOSQRS/
> It runs on my machine with this code but it gives wrong ans on their
> site.
>
> #include<iostream>
> #include<math.h>
>
> using namespace std;
>
> int main()
> {
> int i=0,j=0,X=0,t=0,count=0;
> cin>>t;
> while(t--)
> {
> cin>>X;
> i=sqrt(X);
> j=sqrt(X-i*i);
> while(i>=0 && i>=j)
> {
> if((i*i)+(j*j)==X)
> {count++;}
> i--;
> j=sqrt(X-i*i);
>
> }
> if(count>0)
> cout<<"Yes";
> else cout<<"No";
> count=0;
> cout<<endl;
> }
> return 0;
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.