login
Primes which are anagrams of squares.
2

%I #11 Feb 18 2024 13:41:03

%S 61,163,211,487,613,619,631,691,829,1237,1279,1297,1327,1483,1489,

%T 1621,1693,1723,1861,2029,2053,2089,2137,2161,2179,2251,2371,2467,

%U 2503,2521,2539,2593,2647,2713,2719,2731,2791,2917,2953,2971,3163,3169,3217,3259

%N Primes which are anagrams of squares.

%C 211 is in the sequence because it is a prime number and 121 (an anagram of 211) is a square: 11*11.

%C 829 is in the sequence because it is a prime number and 289 (an anagram of 829) is a square: 17*17.

%C 409 is NOT in the sequence because, although it is a prime and 49 is a square, 49 is not an anagram of 409 because it does not contain the digit zero. In other words, an anagram of a prime, for purposes of this sequence, must have the same number of digits as the prime has. - _Harvey P. Dale_, Aug 29 2017

%H Michael S. Branicky, <a href="/A161853/b161853.txt">Table of n, a(n) for n = 1..10923</a> (all terms with <= 6 digits; terms 1..1000 from Harvey P. Dale)

%t pasQ[n_]:=AnyTrue[Sqrt[#]&/@Select[FromDigits/@Permutations[ IntegerDigits[ n]],IntegerLength[#]==IntegerLength[n]&],IntegerQ]; Select[Prime[ Range[ 500]],pasQ] (* Requires Mathematica version 10 or later *) (* _Harvey P. Dale_, Aug 29 2017 *)

%o (Python)

%o from sympy import primerange

%o from itertools import count, takewhile

%o def hash(n): return "".join(sorted(str(n)))

%o def aupto_digits(d):

%o squares = takewhile(lambda x:x<10**d, (i*i for i in count(1)))

%o primes = primerange(1, 10**d)

%o S = set(map(hash, squares))

%o return [p for p in primes if hash(p) in S]

%o print(aupto_digits(4)) # _Michael S. Branicky_, Feb 18 2024

%K nonn,base

%O 1,1

%A _Claudio Meller_, Jun 20 2009