"Everyday Learning" "Euler function" a problem with the codevs2296 honor solution Guard

Source: Internet
Author: User


Reprint please specify source [ametake copyright all]http://blog.csdn.net/ametake Welcome to see

Title Source: SDOI2008

The article is very serious plagiarism, so I'll bring the copyright information

First question.

Topic description Narrative Description

As a sports commissioner. C June is responsible for the training of the Guard of Honor. The Guard of Honor is composed of the students of N * N Square, in order to ensure that the team uniform in the March, C June will follow the guard of honor of the left rear, according to his line of sight and the number of students to infer whether the team is neat (for example).

Now. C June wants you to tell him the number of students you can see when the team is neat.

Enter descriptive narrative input Description

A total of a number n.

output descriptive narrative outputs Description

A total of a number, that is, c June should see the number of students.

Example Enter sample input

4

Example outputs sample output

9


data size & Hint

For 30% of data, 1<n<1000

For 100% of data, 1<n<40000


This topic at first glance very take off hand, in fact it is not difficult to find, each line to see the first person is that every possible slope can only see a person .

This problem becomes the number of slopes that may exist. What does the slope mean? Since each point is represented in coordinates, the slope is y/x, assuming that the maximum common factor of x and Y is 1, i.e. gcd (x, y) = 1, then it must be the first point on this slope.

Since assuming their maximum common factor is not 1, for example, 2, then x and Y can be about 2, (4,2) can become (2,1). Therefore (4,2) is not the first point on this slope.

So how many gcd (x, y) =1 points? We have found that the whole picture is symmetric about y=x, so just consider the following half. The case with a slope of 0 or n is very special. On or edge of the axis of symmetry, first ruled out. The other points that we observe can be found on each column, the horizontal axis x unchanged,y<x, and this column appears on the new slope of the node satisfies y and x except 1 without other common factor.

that is, Y and x coprime. how many x coprime y are on each column? There is a Euler function phi (x).

Euler function: For a positive integer n, the Euler function is less than or equal to the number of n coprime number in the number.

such as φ (8) = 4. Since 1,3,5,7 are both and 8 coprime.

Therefore, we only need to ask the 2 to n-1 Euler function, multiplied by 2 plus the remaining edges and three points on the symmetric axis, the correct results can be obtained.


This problem tells us: when encountering gcd=1, we should consider the Euler function

On the code.


Here's a reference to the Euler function template of ghy1953 concise and clear erato chromatography and Euler's function combine once
-also to the death of Ming Sheng. The bastard is heavier than the same.

Copyright NOTICE: Reprint Please specify source [ametake All rights reserved]http://blog.csdn.net/ametake Welcome Word

"Everyday Learning" "Euler function" a problem with the codevs2296 honor solution Guard

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.