Algorithm

素数筛选

/*************************************************************************
     File Name: test.c
     Author: cwj
     Mail: [email protected]
     Created Time: Sat 14 Oct 2017 07:45:57 PM CST
 ************************************************************************/
 //普通筛选法
#include
int prime[100000000];
int vis[100000000];
int main()
{ 
   int primeIndex=0;  
   freopen("prime.txt","w",stdout);
    for (int i = 2; i < 100000000; ++i) {
        if(!vis[i])prime[primeIndex++]=i;

        for (int j = i*2; j <100000000; j+=i) {
            vis[j]=1;
        }
    }
   for (int i = 0; i < primeIndex; ++i) {
          printf("%d",prime[i]+" ");
   }
    return 0;
}
//欧拉线性筛选法
#include
int prime[100000000],vis[100000000];
int main()
{
    freopen("prime.txt","w",stdout);
   //线性素数筛
    int top=0;
    for(int i=2;i<=100000000;i++)
    {
        if(!vis[i])
            prime[top++]=i;
        for(int j=0;j
/*************************************************************************
     File Name: C\C++/exercise.cpp
     Author: cwj
     Mail: [email protected]
     Created Time: Fri 20 Oct 2017 02:39:30 PM CST
 ************************************************************************/

#include
#include
#include
#include
#include
#include
#include
using namespace std;

const int maxn=100+10;

struct Point{
    int x,y;
    Point(int x=0,int y=0):x(x),y(y){}
};
Point operator +(const Point& A,const Point& B){
    return Point(A.x+B.x,A.y+B.y);
}
ostream& operator << (ostream &out,const Point &p){
    out<<"("<
T sum(T*begin,T*end){
    T ans=0;
    for (T*p=begin;p!=end;p++) {
        ans=ans+*p;
    }
    return ans;
}
int A[maxn];
int temp[10000000];
int main(int argc, char *argv[])
{
    srand(time(NULL));
    vector x;
    x.push_back(20);
    for(vector::iterator i = x.begin(); i != x.end(); ++i){
        printf("%d \n",x.size());      
    }
    set  seta;
    for (int i = 0; i < 100; ++i) {
     seta.insert(rand());
    }
    int index=0;
    for (set::iterator it=seta.begin();it!=seta.end();++it) {
        cout<<*it<<"\n";
        index++;
    }
    cout<>x)sum+=x;
        cout<

你可能感兴趣的:(Algorithm)