I have a question for everyone. I have this problem statement where in given, x^2 + y^2 = c
is the equation, you have to optimally find the tuples (x,y)
such that the equation holds true.
Given a variable c, whose value is known, you have to find the values (x,y)
. So suppose if you have c=0
, then x=0
and y=0
. Suppose you have c=2
, then (x,y)
are (-1,1)
(1,-1)
, (-1,-1)
, (1,1)
. Now we have to find such values.
You just have to count the amount of such tuples for a given value of c
.
Now I wrote the application as such:
int getCount(int c) {
int count=0,temp=-1000;
for(int i=-n;i<n-1;i++) {
for(int j=-n,j<n;j++) {
temp= i^2+j^2;
if(temp==c) {
count++;
System.out.println(i+" "+j);
}
}
}
}
Is there any optimum way to do this?
Please let me know.Tanks!