Infinite sets P and Q of primes are described, p ⊂ Q. For any natural number n it can be decided if n∈ p in (deterministic) time O((log n 9). This answers affirmatively the question of whether there exists an infinite set of primes whose membership can be tested in polynomial time, and is the main result of the paper. Also, for every n∈Q.we show how to produce at random, in expected time O((log n)3), a certificate of length O(logn) which can be verified in (deterministic) time O((log n) 3); this is less than the time needed for two exponentiations and is much faster than existing methods. Finally it is important that P is relatively dense (at least cn1/3logn elements less than n). Elements of Q in a given range may be generated quickly, but it would be costly for an adversary to search Qin this range; this could be useful in cryptography.