欧拉函数裸题
可惜我太久没做题忘了欧拉函数是什么了...
注意判断一下n = 1的情况就好了
#include <cstdio> using namespace std; const int N = 40010; typedef long long ll; ll phi[N]; int n; inline void GetPhi() { for (int i = 2; i < n; i++) if (!phi[i]) for (int j = i; j < n; j += i) { if (!phi[j]) phi[j] = j; phi[j] -= phi[j] / i; } } int main() { scanf("%d", &n); GetPhi(); ll ans = 0; for (int i = 2; i < n; i++) ans += phi[i]; ans *= 2; if (n >= 2) ans += 3; printf("%lld", ans); return 0; }
luogu P2158 [SDOI2008]仪仗队 (欧拉函数)
原文:https://www.cnblogs.com/cminus/p/12255834.html