1 #include <algorithm> 2 #include <iostream> 3 #include <iomanip> 4 #include <cstring> 5 #include <cstdlib> 6 #include <climits> 7 #include <sstream> 8 #include <fstream> 9 #include <cstdio> 10 #include <string> 11 #include <vector> 12 #include <queue> 13 #include <cmath> 14 #include <stack> 15 #include <map> 16 #include <set> 17 18 using namespace std; 19 typedef pair<int,int> II; 20 typedef vector<int> IV; 21 typedef vector<II> IIV; 22 typedef vector<bool> BV; 23 typedef long long i64; 24 typedef unsigned long long u64; 25 typedef unsigned int u32; 26 #define For(t,v,c) for(t::const_iterator v=c.begin(); v!=c.end(); ++v) 27 #define IsComp(n) (_c[n>>6]&(1<<((n>>1)&31))) 28 #define SetComp(n) _c[n>>6]|=(1<<((n>>1)&31)) 29 const int MAXP = 46341; //sqrt(2^31) 30 const int SQRP = 216; //sqrt(MAX) 31 int _c[(MAXP>>6)+1]; 32 IV primes; 33 void prime_sieve() { 34 for ( int i = 3; i <= SQRP; i += 2 ) 35 if ( !IsComp(i) ) for ( int j = i*i; j <= MAXP; j+=i+i ) SetComp(j); 36 primes.push_back ( 2 ); 37 for ( int i = 3; i <= MAXP; i += 2 ) if ( !IsComp(i) ) primes.push_back ( i ); 38 } 39 int euler_phi ( int n ) { 40 int ans = n; 41 int sn = sqrt ( n ); 42 For ( IV, it, primes ) { 43 int prime = *it; 44 if ( prime > sn ) break; if ( n % prime ) continue; 45 for ( ; n%prime == 0; n/= prime ); 46 ans /= prime; 47 ans *= (prime-1); 48 sn = sqrt(n); 49 } 50 if ( n > 1 ) ans /= n, ans *= (n-1); 51 return ans; 52 } 53 i64 sum[4000050],phi[4000050],f[4000050]; 54 int main() 55 { 56 prime_sieve ( ); 57 i64 n,i,j,len,d; 58 for(i=2;i<=4000000;i++) 59 phi[i]=euler_phi(i); 60 memset(f,0,sizeof(f)); 61 for(i=1;i<=4000000;i++) 62 { 63 for(j=i;j<=4000000;j+=i) 64 f[j]+=i*phi[j/i]; 65 } 66 sum[2]=1; 67 for(i=3;i<=4000000;i++) 68 sum[i]=f[i]+sum[i-1]; 69 while(scanf("%lld",&n)!=EOF&&n) 70 { 71 printf("%lld\n",sum[n]); 72 } 73 return 0; 74 }