title: Find the greatest prime number with 7 as the last digit in {1, ..., n}
body: <p>Let's suppose n is an integer around 250000. Using Java, I need to find the greatest prime number that ends with 7 and belongs to {1, ..., n}. Also, I need to keep an eye on computational complexity and try to lower it as much as I can. 
  So I was thinking of using Sieve of Eratosthenes for n, and then just checking my array of bool values </p>
  
  <pre><code>int start = (n % 10 &lt; 7 ? n - (n % 10 + 3) : n - (n % 10 - 7) )
      for (int i = start; i &gt;= 0; i-= 10){ 
          if(primes[i]) 
              return i;
  }
  </code></pre>
  
  <p>It would keep the whole thing simple i guess, but I was wondering what would be the more efficient approach be. Unless there is a way to easily avoid having an array, but I couldn't think of any.</p>