Integer Circles 2

Given the equation of a circle as x 2 + y 2 = 1234567 { x }^{ 2 }+{ y }^{ 2 }=1234567 .How many points inside the the circle have integer coordinates?

This problem is a part of my set The Best of Me


The answer is 3878561.

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.

5 solutions

Drop TheProblem
Oct 25, 2014
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{int conta=0;
for(int x=-1111;x<=1111;x++) 
   for(int y=-1111;y<=1111;y++)
      if(x*x+y*y<1234567)conta++;
cout<<conta;
return 0;
}

c o n t a = 3878561 \boxed{conta=3878561}

Manit Kapoor
Sep 24, 2014

use this easy program(easy for us hard on complier)

include<stdio.h>

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); }

Swapnil Bhargava
Sep 19, 2014
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include<iostream>
#include<cmath>
#define radius 1111
using namespace std;
int main()
{
    long long int ans=0;
    int i;
    for(i=1;i<=radius;i++)
    {
        ans+=(long long int)floor(sqrt(1234567-(i*i)));
    }
    ans*=4;//for the 4 quadrants
    ans+=(radius*4)+1;//number of integer points on the axes(1111x4) and the origin
    cout<<ans;
} 

Kenny Lau
Sep 16, 2014

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 . . .
Siddharth G
Aug 28, 2014
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>                                                    
#include<cmath>                                                                                    
using namespace std;                                                                                      
int main()                                                                              
 { long long int x,y,z,i,j,k;                     
  cin>>z;
  k=0; 
  for(x=0;x<=z;x++)                                                                       
    {if (x*x<=z && (x+1)*(x+1)>z)  
        y=x;      
     else                                  
         continue;
       }    
       for(i=-y;i<=y;i++)
      {for(j=-y;j<=y;j++)
         {if ((i*i)+(j*j)<=z)
            k=k+1;
        else
            continue;}
      }
 cout<<k; 
 return 0;
}  

Non-computer solutions?

Jayakumar Krishnan - 6 years, 9 months ago

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?

Jayakumar Krishnan - 6 years, 9 months ago

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 < = 1234567 x^2+y^2 <= 1234567

Siddharth G - 6 years, 9 months ago

Log in to reply

WoW! NICE2K....How do you know so much C++? How many languages do you know to code in?

Jayakumar Krishnan - 6 years, 9 months ago

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!

Siddharth G - 6 years, 9 months ago

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,

Jayakumar Krishnan - 6 years, 9 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...