Created
February 21, 2014 01:27
-
-
Save Totoro97/9127092 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
#define intl long long | |
#define maxn 10000100 | |
using namespace std; | |
int i,j,k,l,m,n,top; | |
int pri[maxn],done[maxn]; | |
intl phi[maxn],ans; | |
int main() { | |
freopen("2818.in","r",stdin); | |
freopen("2818.out","w",stdout); | |
scanf("%d",&n); | |
for (i = 2; i <= n; i++) { | |
if (!done[i]) { | |
pri[++top] = i; | |
phi[i] = (intl) (i - 1); | |
} | |
for (j = 1; j <= top && i * pri[j] <= n; j++) { | |
done[i * pri[j]] = 1; | |
if (!(i % pri[j])) { | |
phi[i * pri[j]] = phi[i] * (intl) pri[j]; | |
break; | |
} | |
else phi[i * pri[j]] = phi[i] * (intl) (pri[j] - 1); | |
} | |
} | |
for (i = 1; i <= n; i++) phi[i] += phi[i - 1]; | |
for (i = 1; i <= top; i++) { | |
ans += phi[n / pri[i]]; | |
} | |
(ans *= (intl) 2) += (intl) top; | |
printf("%lld",ans); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment