The upper triangle line is exactly the Euler function of [1,n-1]
Http://www.luogu.org/problem/show?pid=2158#sub
1 //#pragma COMMENT (linker, "/stack:167772160")2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <iostream>6#include <queue>7#include <stack>8#include <cmath>9#include <Set>Ten#include <utility> One#include <algorithm> A#include <vector> -#include <map> - //#include <malloc.h> the using namespacestd; - #defineCLC (A, B) memset (A,b,sizeof (a)) - #defineLL Long Long - voidfre () { +Freopen ("In.txt","R", stdin); - } + Const intINF =0x3f3f3f3f; A #defineEPS 1e-8 at //const Double PI = ACOs ( -1); - ConstLL mod = 1e9+7; -InlineintR () { - intx=0, f=1;CharCh=GetChar (); - while(ch>'9'|| ch<'0'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} in returnx*F; - } to Const intmaxn=1e7; + Const intn=40000; - BOOLVIS[MAXN]; the intPHI[MAXN]; * intPRIME[MAXN]; $ inttot;Panax Notoginseng voidP_pri () { - //CLC (vis,0); thephi[1]=1; +tot=0; A inti,j; the for(i=2; i<=n;i++){ + if(!Vis[i]) { -prime[tot++]=i; $phi[i]=i-1; $ } - for(j=0; j<tot;j++){ - if(i*prime[j]>n) Break; thevis[i*prime[j]]=true; - if(i%prime[j]==0){Wuyiphi[i*prime[j]]=phi[i]*Prime[j]; the Break; - } Wu Else{ -phi[i*prime[j]]=phi[i]* (prime[j]-1); About } $ } - } - } - A intMain () { + intN; the LL ans; -ans=0; $scanf"%d",&n); the P_pri (); the for(intI=1; i<n;i++){ theans+=Phi[i]; the } -cout<<ans*2+1<<Endl; in return 0; the}
P2158 [SDOI2008] honor guard linear sieve (Euler function and prime table)