Sieve the Euler function and you can do it.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define REP (i,s,t) for (int i=s;i<=t;i++) #define CLR (x,c) memset (x,c,sizeof (x)) const int Nmax=40005;int Phi[nmax ],prime[nmax];bool vis[nmax];void init () { phi[1]=1;int cnt=0; Rep (i,2,nmax-1) { if (!vis[i]) prime[++cnt]=i,phi[i]=i-1; Rep (j,1,cnt) { int x=prime[j]; if (I*x>=nmax) break; Vis[i*x]=1; if (i%x==0) { phi[i*x]=phi[i]*x;break; } else phi[i*x]=phi[i]*phi[x]; } } Rep (i,1,100) printf ("%d", Phi[i]);p rintf ("\ n");} int main () { init (); int ans=0,n;scanf ("%d", &n); Rep (i,1,n-1) ans+=phi[i]; printf ("%d\n", ans*2+1); return 0;}
2190: [SDOI2008] Honor guard Time limit:10 Sec Memory limit:259 MB
submit:2560 solved:1631
[Submit] [Status] [Discuss] 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 [Submit] [Status] [Discuss]
bzoj2190: [SDOI2008] Honor guard