1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| void sieve() { tot = 1; memset(vis, 0, sizeof(vis)); low[1] = 1; G[1] = 函数G(n) n=1时的定义 for (int i = 2; i <= mxn; i++) { if (!vis[i]) { pri[tot++] = i; low[i] = i; G[i] = 函数G(n) n=质数时的直接定义 }
for (int j = 1; j <= tot && pri[j] * i <= mxn; j++) { vis[i * pri[j]] = 1; if (i % pri[j] == 0) { low[i * pri[j]] = low[i] * pri[j]; if (i == low[i]) G[i * pri[j]] = else G[i * pri[j]] = G[i / low[i]] * G[pri[j] * low[i]]; break; } low[i * pri[j]] = pri[j]; G[i * pri[j]] = G[i] * G[pri[j]]; } } }
|