求1亿以内最大质数c=100000000b=2a=2while(1<c<=100000000): while(b<c): if (c%b==0):break b=b+1 if(b>=c): if(a<c): a=c c=c-1print(a)为什么输出为99999993?
2 回答
慕标5832272
TA贡献1966条经验 获得超4个赞
#include <iostream>#include <vector> using namespace std; const unsigned int MAX_NUM=100; void Prime(vector<bool> &numbers,vector<int> &primes){ for(unsigned int i=2;i<=MAX_NUM;i++){ if(numbers[i]==false){ primes.push_back(i); // multiple of i for(unsigned int j=i;j<=MAX_NUM;j+=i) numbers[j]=true; } }} int main(){ vector<bool> numbers(MAX_NUM,false); vector<int> primes; Prime(numbers,primes); vector<int>::iterator it=primes.begin(); for(;it!=primes.end();it++){ cout<<*it<<endl; } return 0;}
例子参考
添加回答
举报
0/150
提交
取消