I have a number of random numbers. The range is actually user-defined, but it will be up to 1000 integers. They fit into this:
vector<int> n
and the values are inserted as follows:
srand(1);
for (i = 0; i < n; i++)
v[i] = rand() % n;
I create a separate function to find all non-zero values. That's what I have now, but I know that this is completely wrong, because I get both simple and compound in the series.
void sieve(vector<int> v, int n)
{
int i,j;
for(i = 2; i <= n; i++)
{
cout << i << " % ";
for(j = 0; j <= n; j++)
{
if(i % v[j] == 0)
cout << v[j] << endl;
}
}
}
This method usually worked when I just had a series of numbers from 0-1000, but it doesn't seem like it will work now that I have numbers from order and duplicates. Is there a better way to find non-empty numbers in a vector? I am tempted to just create another vector, fill it with n numbers and just find nonproliferation of primes like that, but will it be inefficient?
, 0-1000 , 0- , , , ?
void sieve(vector<int> v, BST<int> t, int n)
{
vector<int> v_nonPrime(n);
int i,j;
for(i = 2; i < n; i++)
v_nonPrime[i] = i;
for(i = 2; i < n; i++)
{
for(j = i + 1; j < n; j++)
{
if(v_nonPrime[i] % j == 0)
cout << v_nonPrime[i] << endl;
}
}
}