Sdoi2008 Guard of Honor

Source: Internet
Author: User

Title Description Description
As a sports Commissioner, C June is responsible for the training of the honor guard. Guard of Honor is composed of students of N * N of the square, in order to ensure that the procession uniform, c June will follow the guard of Honor's left rear, according to the number of students in the line of sight to determine whether the team is neat (such as).
Now, C-June wants you to tell him the number of students you can see when the team is neat.
  

Enter a description input Description
A total of a number n.

outputs description output Description
A total of a number, that is, c June should see the number of students.

sample input to sample
4

sample output Sample outputs
9

Data Size & Hint
For 30% of data, 1≤n≤1000
For 100% of data, 1≤n≤40000

Solving
The lower left corner is (0,0), if (x, y) is visible, then gcd (x, y) = 1, analytic geometry or two-dimensional vector something to think about, you can figure it out.
Press Y=x to divide the coordinate system into two halves. For each half, the X column always has phi (x) visible, and (similarly, the Y line always has phi (Y) to be seen.) These two are available with one) (Phi for Euler functions)
This will add Phi (2~n-1), multiply by 2, plus (0,1) (1,0) (three) points can be answered

    • Code:
#include <cstdio>#include <algorithm>#define LL unsigned long longusing namespace STD;Const intMAXN =40050;intN;ll Phi[maxn], ans;voidReadint&a) {intf =1;Charch = getchar (); A =0; while(Ch <' 0 '|| CH >' 9 ')    {if(ch = ='-') F =-1;    ch = getchar (); } while(Ch >=' 0 '&& CH <=' 9 ') {a = a *Ten+ CH- -;    ch = getchar (); } a *= F;}voidWrite (ll a) {inttop =0;Charch[ -];if(A <0)    {Putchar('-');    A =-A; } Do{ch[top++] = a%Ten+ -; A/=Ten; } while(a); while(top--)Putchar(Ch[top]);Putchar(' \ n ');}voidEulerphi (intA//Sieve method to find Euler function{phi[1] =1; for(inti =2; I <= A; ++i)if(Phi[i] = =0) for(intj = i; J <= A; J + = i) {if(Phi[j] = =0) Phi[j] = j; PHI[J] = phi[j]/I * (i-1); }}voidInit () {read (n); Eulerphi (n);}voidWork () { for(inti =2; I < n;    ++i) ans + = phi[i]; Write (ANS *2+3);}intMain () {init (); Work ();return 0;}

Sdoi2008 Guard of Honor

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.