Algorithm to add all lucky numbers under [N] to a Vector
It is fairly straightforward to generate a vector with all the values.  First, you should treat all the same length numbers as a group.  The values 4 and 7 would be in a singledigit vector.  To get the twodigit vector, simply go through the previous vector, multiplying each by 10 and then adding 4 to push back a value and add 7 to push back another value.

vector&lt;int&gt; lucky;
vector&lt;int&gt; current;
vector&lt;int&gt; next;
current.push_back(4);
current.push_back(7);
lucky.push_back(4);
lucky.push_back(7);
int value=0;
while(value &lt; N)
{
   for(unsigned int i=0;i&lt;current.size();++i)
   {
       value=current[i]*10+4;
       next.push_back(value);
       lucky.push_back(value);
       value=current[i]*10+7;
       next.push_back(value);
       lucky.push_back(value);
   }

   current=next;
   next.clear();
}