## Thrice Unfactorised

The following problem appeared as ENIGMA 1168 in New Scientist 5 January 2002

## THRICE UNFACTORISED

### Richard England

I have found a four-digit number such that it is impossible to factorise the numbers formed by its first digit or last digit or first two digits or middle two digits or last two digits or first three digits or last three digits or all four digits. In other words all those eight numbers are prime except that either or both of the single-digit numbers may be unity.

Harry and Tom have also found such a four-digit number. The four-digit numbers that we have found are all different; but Harry's number uses the same digits as Tom's number, though in a different order. Which four-digit number have I found?

We might use SQL to generate prime numbers - but it's easier and quicker to get some from elsewhere such as James Edwards at Bristol or Chris Caldwell at the University of Tennessee.

The table prime contains the 1300 small primes including all the four digit primes.

 1. Check that the tables primes exists by viewing all primes less than 50. SELECT i FROM prime WHERE i<50 Results
 2. The SUBSTR function in Oracle may be used to extract digits. SELECT i, SUBSTR(i,1,1) "first1", SUBSTR(i,4,1) "last1", SUBSTR(i,1,2) "first2", SUBSTR(i,2,2) "mid2", SUBSTR(i,3,2) "last2", SUBSTR(i,1,3) "first3", SUBSTR(i,2,3) "last3" FROM prime WHERE i between 1000 AND 1100 Results