息止


私信TA

用户名:2194669092

访问量:976

签 名:

等  级
排  名 11421
经  验 970
参赛次数 0
文章发表 14
年  龄 0
在职情况 学生
学  校 南昌工程学院
专  业

  自我简介:

TA的其他文章

解题思路:代码是几乎纯复制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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区