C++ primes using find_if
Jul 18, 2013 at 11:21am UTC
First of all i'm a beginner in progamming.
I need to make a calculator for aritmetics, combinatorials and number strings.
I'm stuck at the primes because i need to use some algorithm and i didnt understand them.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
TestPrim::TestPrim(Uint val)
{
_val = val;
_stopVal = sqrt(double (_val));
}
TestPrim& TestPrim::operator ++()
{
_val += 2;
_stopVal = sqrt(double (_val));
return *this ;
}
bool TestPrim::operator () (Uint divizor)
{
if ( divizor > _stopVal || 0 == _val % divizor )
{
return true ;
}
}
bool operator > (Uint val, const TestPrim &src)
{
if (val > src._stopVal)
{
return true ;
}
}
TestPrim::operator Uint ()
{
return _val;
}
void Prime::CalculeazaValori(int index)
{
while (_elemente.size() < _count)
{
if (_elemente.size() == 0 )
{
_elemente.push_back(2);
_elemente.push_back(3);
}
TestPrim testPrim = _elemente.back() + 2;
for (testPrim; Uint index< _count;++testPrim)
{
vector<Uint>::iterator TIterator=find_if(TVint.begin(),TVint.end(),testPrim);
if (TIterator > testPrim )
{
_elemente.push_back(testPrim);
}
}
}
}
If someone could help me i will be gratefull.
Last edited on Jul 18, 2013 at 11:29am UTC
Topic archived. No new replies allowed.