标签:const bsp span get class nbsp 线性筛 for style
1 const int maxn = 1e6+10; 2 3 int prime[maxn]; 4 int vis[maxn]; 5 int cnt; 6 7 void is_prime() {//线性筛 8 for (int i = 2; i < maxn; i++) { 9 if (!vis[i]) prime[cnt++] = i; 10 for (int j = 0; j < cnt && i * prime[j] < maxn; j++ ){ 11 vis[i * prime[j]] = 1; 12 if (i % prime[j] == 0) break; 13 } 14 } 15 } 16 17 18 int get_num(int x) {//获得1到x区间内x因数的个数 19 int res = 1; 20 for (int i = 0; i < cnt && prime[i] * prime[i] <= x; i++) { 21 if (x % prime[i] == 0) { 22 int num = 0; 23 while (x % prime[i] == 0) { 24 num++; 25 x /= prime[i]; 26 } 27 res *= (1 + num); 28 } 29 } 30 if (x > 1) res *= 2ll; 31 return res; 32 }
标签:const bsp span get class nbsp 线性筛 for style
原文地址:https://www.cnblogs.com/hznudreamer/p/12884388.html