Question: I added buttons to xib as normal using iOS 6 SDK and Xcode 4.5.

When I run the app on iOS 6 simulator, there is no problem. But when I run it on the iOS 5.x simulator (or device), the title on the button always disappears(not every time). Lots of my view controllers have this problem.

![enter image description here](https://i.stack.imgur.com/QxPfV.png)

**PS: Only Custom type button have this problem**

![enter image description here](https://i.stack.imgur.com/wF7Xf.png)

**Found the reason:**  

 [[UIButton appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:@"取消" forState:UIControlStateNormal]

Answer: 
No, that's trial division which is much worse than the sieve of eratosthenes in time-complexity. Its space complexity is *a bit* better, but, since primes are about `n/log(n)` you are not saving huge quantities of memory. also the sieve can be done using bit-vectors which reduce the *constants* by 32/64 times(and thus for *practical* purposes it might be even better).

---

Small benchmark that shows the difference in timings:

```
>>> timeit.timeit('primes_list(1000)', 'from __main__ import primes_list', number=1000)
0.901777982711792
>>> timeit.timeit('erat(1000)', 'from __main__ import erat', number=1000)
0.2097640037536621

```

As you can see, even with `n=1000` eratosthenes is more than 4 times faster.
If we increase the search up to `10000`:

```
>>> timeit.timeit('primes_list(10000)', 'from __main__ import primes_list', number=1000)
50.41101098060608
>>> timeit.timeit('erat(10000)', 'from __main__ import erat', number=1000)
2.3083159923553467

```

Now eratosthenes is 21 times faster. As you can see it's clear that eratosthenes is **much** faster.

---

using numpy arrays it's quite easy to reduce the memory by 32 or 64(depending on your machine architecture) and obtain much faster results:

```
>>> import numpy as np
>>> def erat2(n):
...     ar = np.ones(n, dtype=bool)
...     ar[0] = ar[1] = False
...     ar[4::2] = False
...     for j in xrange(3, n, 2):
...             if ar[j]:
...                     ar[j**2::2*j] = False
...     return ar.nonzero()[0]
... 
>>> timeit.timeit('erat2(10000)', 'from __main__ import erat2', number=1000)
0.5136890411376953

```

An other 4 times faster than the other sieve.
Since `range` in Python 2 returns a list, your algorithm's space complexity is still `O(n)`, so it is not more space efficient (at least not asymptotically). If you used xrange (or range in Python 3), it would be somewhat more space efficient because you'd only be storing the primes - not all numbers up to `n`.

Your time efficiency will be worse than a sieve either way.