1 /** 2 * Fuck you. 3 * I love you too. 4 */ 5 #include<bits/stdc++.h> 6 #define lson i<<2 7 #define rson i<<2|1 8 #define LS l,mid,lson 9 #define RS mid+1,r,rson 10 #define mem(a,x) memset(a,x,sizeof(a)) 11 #define gcd(a,b) __gcd(a,b) 12 #define ll long long 13 #define ull unsigned long long 14 #define lowbit(x) (x&-x) 15 16 const int INF = 0x3f3f3f3f; 17 const int EXP = 1e-8; 18 const int n = 1e5 + 5; 19 const int MOD = 1e9 + 7; 20 const int MAXN = 1e5 + 5; 21 22 using namespace std; 23 24 bool notprime[MAXN]; //是否为素数 25 int prime[MAXN]; //素数表 26 int phi[MAXN]; //欧拉函数表 27 28 void euler_sieve () { 29 int tot = 0; 30 mem (notprime, 0); 31 for (int i = 2; i < MAXN; ++i) { 32 if (!notprime[i]) { 33 prime[tot++] = i, phi[i] = i - 1; 34 } 35 for (int j = 0; j < tot; ++j) { 36 if (i * prime[j] > MAXN) { 37 break; 38 } 39 notprime[i * prime[j]] = 1; 40 if (i % prime[j] == 0) { 41 phi[i * prime[j]] = phi[i] * prime[j]; 42 break; 43 } else { 44 phi[i * prime[j]] = phi[i] * (prime[j] - 1); 45 } 46 } 47 } 48 } 49 50 int main() { 51 euler_sieve(); 52 for (int i = 2; i <= 10; i++) { 53 cout << phi[i] << endl; 54 } 55 return 0; 56 }
原文地址:https://www.cnblogs.com/chunibyo/p/9385864.html
时间: 2024-11-03 03:33:33