"BZOJ2190" "SDOI2008" honor Guard

Source: Internet
Author: User

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.

Input

A total of a number n.

Output

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

Sample Input4

Sample Output9


HINT

"Data size and conventions" for 100% of data, 1≤n≤40000

Source

Arithmetical

idea: Look at the picture, is symmetrical, with the diagonal as the axis of symmetry, not to see the special three points, the calculation found that the points on the line to meet the Euler function, so the linear sieve to 2~n-1 Eulerian function can, finally do not forget the symmetry and special three points. Time 10sec not linear sieve also OK?
1#include <iostream>2#include <cstdio>3#include <cstring>4 #defineN 400005 using namespacestd;6 intflag[n+Ten],prime[n+Ten],phi[n+Ten];7 intN,ans;8 voidErphi ()9 {Ten     intk=1; Onememset (Flag,0,sizeof(flag)); A      for(intI=2; i<=n;i++) -     { -         if(!flag[i]) prime[k++]=i,phi[i]=i-1; the          for(intj=1; j<k&&i*prime[j]<n;j++) -         { -flag[i*prime[j]]=true; -             if(i%prime[j]==0)     +             { -phi[i*prime[j]]=phi[i]*Prime[j]; +                  Break; A             } at             Elsephi[i*prime[j]]=phi[i]* (prime[j]-1); -         } -     } -     return; - } - intMain () in { -scanf"%d",&n); to Erphi (); +      for(intI=2; i<n;i++) -ans+=Phi[i]; theprintf"%d\n", ans*2+3); *     return 0; $}

"BZOJ2190" "SDOI2008" honor 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.