Fermat's theorem will be better for this problem..:)
Cheers ~ Jeeva ~ On Thu, May 26, 2011 at 12:42 AM, Saikat Debnath <crazysai...@gmail.com>wrote: > I think your problem is you are using int. Use long long. > > > On Thu, May 26, 2011 at 12:29 AM, ricky <moon.afr...@gmail.com> 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 algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> 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 algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.