# A modification of a mathematica code that selects perfect square on the list

Below is a code taken from OEIS that generates integers $n$ such that $\sigma(n)-n\mid (n-1)$.

Select[
Range[2, 250]
, Divisible[#-1, DivisorSigma[1, #]-#]&
]


How can I modify this code in such a way that I only get a particular subset of the generated sequence. The subset I want to get are the perfect squares among those $n$ that are generated above.

• Thanks for your comment @Kuba. Sorry for my english construction. What I want to get is those $n$ generated by the code above that are perfect square. Thanks a lot. Mar 7, 2017 at 7:02
• Some of the integers generated by the code above are: 2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19, 23, 25, 27, 29, 31, 32, 37, 41, 43, 47, 49, 53, 59, 61, 64, 67, 71, 73, 77, 79, 81, 83, 89, 97, 101, 103, 107, 109, 113, 121, 125, 127, 128, 131, 137, 139, 149, 151, 157,. Mar 7, 2017 at 7:03
• From which I want to collect the perfect squares: 4, 16, 25 ... Mar 7, 2017 at 7:04
• I saw your answer. And it works. Been wondering why it works and I am so interested. Can you please explain why? Thanks Mar 7, 2017 at 7:25

Select[Range[2, 15]^2, Divisible[# - 1, DivisorSigma[1, #] - #] &]

{4, 9, 16, 25, 49, 64, 81, 121, 169}

• Ah, I see the code also works. Thanks @Kuba. I just wondering why changing the range to [2,15]^2 will do the trick. I am interested to know. Can you please expalin? Thanks a lot. Mar 7, 2017 at 7:24
• @JrAntalan instead of selecting from all integers we generate a sequece of perfect squares and then do your filtering.
– Kuba
Mar 7, 2017 at 7:26
• Ah, I got it now. Thanks @Kuba Mar 7, 2017 at 10:41

Perhaps:

Select[Range[2, 250],
Divisible[# - 1, DivisorSigma[1, #] - #] &&
Mod[Length@Divisors[#], 2] == 1 &]

• Where is 36? :)
– yode
Mar 7, 2017 at 7:13
• @yode I believe the OP is requesting a subset of the sequence generated and not just the square numbers between 2 and 250 inclusive, else it would be easier to do Range[2,Floor[Sqrt[250]]^2 etc. My interpretation may be wrong. Mar 7, 2017 at 7:16
• Thanks @upbdqn. I will try to run the code. An upvote for your answer. I have another question if its okay with you. What function should I call if I want to break down the list geneated by the code into its prime factorization? Sorry I only know the basics of Mathematica. Mar 7, 2017 at 7:18
• And thank you again. Mar 7, 2017 at 7:18
• @JrAntalan FactorInteger/@result where result is your desired list. Mar 7, 2017 at 7:20
Select[Range[2, 250], EvenQ[Last[InternalPerfectPower[#]]] &]


{4,9,25,36,49,100,121,144,169,196,225}

• Thanks @yode. Indeed the code works. Mar 7, 2017 at 7:14
• An upvote for that. I have additional querry if its okay with you. Is there a function that breaks down the elements of the list into its prime factorizarion? Sorry I just only know simple mathematica codes. Mar 7, 2017 at 7:16
• @JrAntalan FactorInteger`
– yode
Mar 7, 2017 at 7:19