Given the equation of a circle as x 2 + y 2 = 1 2 3 4 5 6 7 .How many points inside the the circle have integer coordinates?
This problem is a part of my set The Best of Me
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
use this easy program(easy for us hard on complier)
void main() { long long int x, y, n1=0, d; for(x=-1200;x<1200;x++){for(y=-1200;y<1200;y++){ d=(x x)+(y y); if(d <= 1234567) { n1++; } } y=0; } printf("\n%lld",n1); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
java code:
public class brilliant201409161915{
public static void main(String args[]){
int count = 0;
for(int x=((int)-Math.sqrt(1234567));x<=((int)Math.sqrt(1234567));x++){
for(int y=((int)-Math.sqrt(1234567));y<=((int)Math.sqrt(1234567));y++){
if(x*x+y*y<1234567) count++;
}
}
System.out.print(" "+count+"\n ");
}
}
output:
3878561
Press any key to continue . . .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Non-computer solutions?
And, hey can you explain the logic of this solution ( @Siddharth G ) ...I dont know...C++ and also did you come up with this question on your own?
Log in to reply
Yup, this my own ques. However, I started doing this as a number theory question, tried for a week, got frustrated, and did it with a program. I was hoping someone would provide a different approach. Coming to the logic, it is just a (partial) brute force for finding all x 2 + y 2 < = 1 2 3 4 5 6 7
Log in to reply
WoW! NICE2K....How do you know so much C++? How many languages do you know to code in?
Log in to reply
@Jayakumar Krishnan – Python too. If you are interested, https://courses.edx.org/courses/MITx/6.00.1x/3T2013/courseware/Week_1/ provides an awesome course!
Log in to reply
@Siddharth G – Uh-oH! it provides an error messages... BTW @Siddharth G -could you provide the name of the course instead,
Problem Loading...
Note Loading...
Set Loading...
c o n t a = 3 8 7 8 5 6 1