500000以内的素数个数 C/C++程序 高手指教!

来源:百度知道 编辑:UC知道 时间:2024/06/02 04:24:42
输入a,b(0<=a,b<=500000),从a到b的素数个数(包括a,b;0,1不算是素数),要完整代码!
最好简洁点儿,我是新手,复杂的看不懂……

----------VC6.0测试通过----加了部分注释--------------------
//Prime.h
#ifndef PRIME_H_
#define PRIME_H_
#include <fstream>
using namespace std;
class Prime
{
public:
Prime(int n1,int n2);
~Prime();
void Process();
void Show(fstream& ofile);
private:
int min,max,num;
int data[200];
bool IsPrime(int elem);
//unsigned long fn(int n);
};
#endif//PRIME_H_

//Prime.cpp

#include <iostream>
#include <fstream>
#include "Prime.h"

using namespace std;

Prime::Prime(int n1,int n2)
:max(n2),min(n1),num(0)
{}

Prime::~Prime()
{}
/********一个定理***********
unsigned long Prime::fn(int n)
{
unsigned long sum(0);
if(n==0)
return 1;
else
{
sum=n*fn(n-1);
return sum;
}

}

bool Prime::IsPrime(int elem)