To check for prime/divisibility you only need to check the prime numbers up to sqrt(n), so for 127 its 2,3,5,7,11 and all are simple digit/divisibility rules, but not hard to do the longer way.
Similar for 2047 if you really wanted to. Youd need to check primes up to 43 and 2,3,5,7,11 are easy. Then its just a case of trying 13,17,19,23, ... and the latter would give.