解题思路:代码是几乎纯复制HzuWH的,因为理解有些困难,我加上注释和我的理解来辅助理解
注意事项:
参考代码:
#include<algorithm> #include<cstdio> #include<iostream> #include<math.h> using namespace std; typedef long long LL; bool isprime(LL num) { if (num < 2) return false; for (int i = 2; i > start >> end; if (end < 2) cout << 0 << endl; else { if (start < 2) start = 2; LL limits = (LL)sqrt((double)end);//开根号 for (LL i = 2; i 2 ? start / i : 2;//i从2开始增大,为了使(N*i从start开始,减少多余计算)(若start<=4时取2,不影响对素数判断) for (; N*i = start) primetable[N*i - start] = true;//合数一定能由一个素数和另一个数相乘得到 }//所以N*i是合数,N*i - start是其所在区间位置 int total = 0; for (LL i = 0; i <= end - start; i++) if (!primetable[i])//为false时素数 total++; cout << total << endl; } }
0.0分
1 人评分