views:

33

answers:

1
#include <iostream> 
#include<map>
using namespace std;
map <long long  , long long> h;
void sieve(long long start,long long size) 
{
    long long i,j;
    for (i=2; i*i <= size; i++) {
           if (!h[i]) {
                   for(j = i+i; j < size ;j+=i) { h[j] = 1; }
           }
    }
    for (i=2; i<size; i++) {
           if (!h[i]) { printf("%lld \n", i); }
    }
}
int main() {
    long long input[2],i=0,n;
    for(i=0;i<2;i++)
     scanf("%lld",&input[i]);      
    sieve(input[0],input[1]);        
    system("pause");
    return 0;
} 
+1  A: 

std::map is certainly not the best choice. Perhaps the infamous std::vector would actually be useful here. Also, using scanf is a bit strange when doing C++ and iostreams. Other than that, the alogrithm is implemented very naively... I assume that is on purpose.

Esben Mose Hansen