If the list is long, the numbers are large, and performance is important, it may be better to search the list backwards until a non-prime is found. This must be base^imax (assuming the list is sorted). It is then straightforward to construct the set of elements which should be removed from the list.

That's bloody beautiful and I feel rather foolish for what I wrote now, but I'll leave my answer so all can see how you trounced me so completely.
–
Mr.Wizard♦Dec 27 '13 at 22:27

@Simon Thank you for your answer. I have studied your method and understands how it works, up to the end. I am not so impressed as Mr.Wizard appears to be, but that is because I could never have come up with this solution and in this form. In the last step you use infix notation which is completely new to me. I understand the infix part in Mr.Wizard's new Method (standing now above) but yr part is more complicated because of the #'s before and after the infix part. Would you be so kind to explain it to me?
–
RombertDec 28 '13 at 14:57

I am answering my interpretation of question. Apologies if I have misunderstood.
If the aim is to retain the largest power of a prime (and not the integer with largest power prime) the following will achieve this:

Note belisarius code which is based on Mod will select largest multiple of base and will remove all powers in above test case and retain 250. Other counter examples can also show this, e.g remove 250 in above and 150 will be retained and all powers removed.

If the aim is to find integer with largest base prime exponent that is a different question.

In my lists are only two ingridients: A: simple primes occurring once and B: powers of a common base prime but they occur also only once and are all present up to the power imax.
–
RombertDec 24 '13 at 8:25

thank you for the clarification. In that case it seems to me Modulus based approach will return a multiple of base that is not a power of base and reject smaller but pure powers of base...
–
ubpdqnDec 24 '13 at 9:01

I studied your answer and like it, however had a little problem in getting it to work (I changed u_Integer into u_ in the arguments of your Module). I agree with your remark about the solution of belisarius using Mod. However, in the lists that I am using only Primes and integer powers of primes will occur. I will also investgate the answers of belisarius and Mr.Wizard , so I did not yet make my choice, which will be rather difficult.
–
RombertDec 27 '13 at 12:28

1

@Rombert ok. My code determines the maximum power of base (b) in the list and then picks from the list either elements which are not integer powers of the base or the maximum ower of the base, where you choose the base, Your case of interest is a prime integer.
–
ubpdqnDec 27 '13 at 13:17

Here is another method based on Simon's answer. It is only slightly longer than his code yet is more efficient for large $imax$ because it eliminates a large number of factors before sorting:

strip3[a_] := Sort @ GatherBy[Divisors @ a, #[[2]] &][[All, -1, -1]]

Timings

To justify the existence of this answer after Simon Woods posted a wonderfully clean method I shall illustrate that there can be a performance advantage to my method, specifically in the case of large $imax$ values.

I have figured out how your methods (new and old) are working. They both work fine! Btw thank you. I just received a new answer from Simon Woods. Something "compeletely" different. Now I have to figure out the precise working of Complement in this case! How long can I wait with my choosing the "winner"? What is the best way to publish my motivation? I often told my students: the best way to learn something new, is to ask a question (;)
–
RombertDec 27 '13 at 17:10

@Rombert You're welcome. I just saw Simon's answer now and it looks like the clear winner. You can wait as long as you like to Accept an answer, but know that you can also change your Accept at any time, and if someone posts a better answer you can (and arguably should) change to Accept to it. I don't know what you meant by "What is the best way to publish my motivation?" Could you clarify?
–
Mr.Wizard♦Dec 27 '13 at 22:24

With publish my motivation, I mean give the argumentation for Accepting that one. Or is it just make yr choice. You know, we are used to say why! Your methods have some advantages in checking whether all the powers of the common base prime are present in the given list or not. So I believe.
–
RombertDec 27 '13 at 22:44

@Rombert You're surely welcome to explain why you chose a particular answer but it's not necessary. I really like clean, concise code so I wish I had thought of Simon's solution. Nevertheless I agree that there are aspects of my (new) method that may be advantageous. In certain circumstances it is more than an order of magnitude faster. I shall update my answer with an example.
–
Mr.Wizard♦Dec 27 '13 at 22:58

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.