language: C++ 4.7.2 (gcc-4.7.2)
date: 578 days 17 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <vector>
#include <cmath>
 
using namespace std;
 
int main()
{
        const int SIZE = 1000000;
        vector<int> intList(SIZE);
        vector<int> primeList(1,1);
 
        for(int i = 0; i < SIZE; i++)
                intList[i] = i;
 
        for(int index = 2; index <= sqrt(static_cast<double>(SIZE)); index++)
                if (intList[index] != 0)
                        for(int index2 = index*index; index2 < SIZE; index2++)
                                if(intList[index2] % index == 0)
                                        intList[index2] = 0;
 
        for(int index  = 1; index < intList.size(); index ++)
                if(intList[index] != 0)
                        primeList.push_back(intList[index]);
 
        cout << "The number of primes less than " << SIZE << " is " << primeList.size() - 1 << "(which includes 1)" << endl;
/*      for(int index = 1; index < primeList.size(); index ++)
                cout << index << '\t' << primeList[index] << endl; */
                return(-1);
}
prog.cpp: In function ‘int main()’:
prog.cpp:22: warning: comparison between signed and unsigned integer expressions