POJ 3090 Visible Lattice Points

Source: Internet
Author: User

POJ 3090 Visible Lattice Points

Description

A lattice point (X,Y) In the first quadrant (XAndYAre integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) (X,Y) Does not pass through any other lattice point. for example, the point (4, 2) is not visible since the line from the origin passes through (2, 1 ). the figure below shows the points (X,Y) With 0 ≤X,Y≤ 5 with lines from the origin to the visible points.

Write a program which, given a value for the size,N, Computes the number of visible points (X <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Vc3ryb25np1_vzw0 + LCA8ZW0 + large + PHN0cm9uZz54PC9zdHJvbmc + large + PHN0cm9uZz5OPC9zdHJvbmc + large "pst"> Input

The first line of input contains a single integerC(1 ≤C≤ 1000) which is the number of datasets that follow.

Each dataset consists of a single line of input containing a single integerN(1 ≤N≤ 1000), which is the size.

Output

For each dataset, there is to be one line of output consisting of: the dataset number starting at 1, a single space, the size, a single space and the number of visible points for that size.

Sample Input

4245231

Sample Output

1 2 52 4 133 5 214 231 32549
 
Train of Thought: in fact, the question has already provided you with a train of thought, that is, the comparison slope. As long as it is a point where the slope does not appear, we can add these points. We find that each more number means an outer layer, we only need to add the points on the outer layer, and the points on the outer layer are symmetric!
So the AC code:
# Include  # Include  # Includeusing namespace std; int a [1005] [1005]; // use an array label to represent the x and y coordinates, use the array value to indicate whether the slope has exceeded int B [1005]; // number of points in the record int gcd (int a, int B) {if (  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.