The topics are as follows:
small easy to have a circle center at the origin of the coordinates, small easy to know the radius of the circle square. Xiao Yi that the dots on the circle and the horizontal ordinate are integers are elegant, small easy now looking for an algorithm to calculate the number of elegant points, please help him.
For example, if the square of the radius is
The elegant points are: (+/-3, +/-4), (+/-4, +/-3), (0, +/-5) (+/-5, 0), altogether 12 points.
<?php
function Countgracepoint ($n) {
$count = 0;
for ($x = 1; $x * $x < $n; $x + +) {
$y = (int) sqrt ($n-$x * $x);
if ($x * $x + $y * $y = = $n) {
$count + +;
}
}
$count *= 4;//Because of the existence of four quadrants, there are four cases,
$x = (int) sqrt ($n);
if ($x * $x = = $n) $count + = 4;//A coordinate of 0, there are four kinds of cases
return $count;
}
Echo Countgracepoint (25);//12
?>
This article is from the "12160707" blog, please be sure to keep this source http://12170707.blog.51cto.com/12160707/1880516
NetEase 2017 School recruit Programming: Elegant dot (php version)