MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayThis problem is related to 1283, Points on a Sphere. In this case, instead of a sphere, you have a circle. Given a radius R, calculate the number of points on the circumference of the circle that have two integer coordinates. For a circle of radius 5, you would have 12 points:

- (0, 5) and (0, -5)
- (5, 0) and (-5, 0)
- (2, 1) and (2, -1)
- (-2, 1) and (-2, -1)
- (1, 2) and (1, -2)
- (-1, 2) and (-1, -2)

Some radii are quite large, so watch out. Good luck!

Loading Solution Map...

1 player likes this problem

3 Comments

Marco Castelli
on 26 Mar 2013

Cases (from 6 to 9) of Test Suite are too long te caltulate: Mathwork's server give a error.

James
on 26 Mar 2013

They can be calculated with relative ease without switch/case or if/then commands. There's just a trick on how to do so.

Marco Castelli
on 27 Mar 2013

Otherwise part of my solution can calculate every small case but with giant radius give error. I will provide a new solution

1 player likes this solution

2 Comments

Jean-Marie SAINTHILLIER
on 28 Mar 2013

Can you explain your solution ?

Tim
on 28 Mar 2013

This is derived from the Mathematica algorithm for sequence A046080 at oeis.org (arrived at from A046109). Instead of factoring (because of the large integers) it checks for divisibility by the various primes (up to 325643, which is enough to handle the test set).

1 Comment