updated answer

previous solution did not return prime
grammar edit

"last" is ambiguous, replaced with largest