1

We call number $N$ a twisted prime if we turn all the 6-es in 9s and all the 9s in 6-es and it remains a prime(If it has no 6-es or 9s it is not twisted). How many twisted primes there are? ($N \leq 20000$)

Source: School friend. Is there a way to really calculate it except counting to 20000?

  • It would seem that this question is about as hard to answer as the question of how many primes in general there are less than 20,000. Just my thought. – Vladhagen Jan 17 '14 at 19:13
  • For $N\le 20000$, how many primes are there having $6$ or $9$ as digits? Do we count a prime as "vacuously twisted" if it has no $6$ or $9$ digits? What happens when the question is changed to consider "mirror primes" as those primes having $2$ or $5$ as digits, and those digits are "mirrored" so that $2$ becomes $5$ and $5$ becomes $2$? – abiessu Jan 17 '14 at 19:15
  • The most efficient way is to use the list of $2262$ precalculated primes $\le 20000$. Then observe, that the $6$ cannot be the last digit. Most primes are not twisted, anyway. The first one is $67$ with $97$. – Dietrich Burde Jan 17 '14 at 19:25
  • 1
    There is no useful way other than counting because a number and its twisted image are more or less unrelated in any useful regard. – Hagen von Eitzen Jan 17 '14 at 19:33
  • Oneliner in mathematica: Length[Select[Range[20000], PrimeQ[#] && PrimeQ[FromDigits[IntegerDigits[#] /. {6 -> 9, 9 -> 6}]] &]] – Listing Jan 17 '14 at 19:58

1 Answers1

1

There are 1224 twisted primes below 20000. There are 89372 twisted primes below $10^7$. In PARI/GP this helps

twist(d)=if(d==9 || d==6, 15-d,d)
tw(n)=if(n<10,twist(n),tw(n\10)*10+twist(n%10))
ac=0;forprime(p=2,20000,q=tw(p);if(q!=p&&isprime(tw(p)),ac++));ac