1
$\begingroup$

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 help in advance.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Jr Antalan Mar 7 '17 at 7:02
  • $\begingroup$ 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,. $\endgroup$ – Jr Antalan Mar 7 '17 at 7:03
  • $\begingroup$ From which I want to collect the perfect squares: 4, 16, 25 ... $\endgroup$ – Jr Antalan Mar 7 '17 at 7:04
  • $\begingroup$ I saw your answer. And it works. Been wondering why it works and I am so interested. Can you please explain why? Thanks $\endgroup$ – Jr Antalan Mar 7 '17 at 7:25
6
$\begingroup$

Why not start with them at the first place?

Select[Range[2, 15]^2, Divisible[# - 1, DivisorSigma[1, #] - #] &]
{4, 9, 16, 25, 49, 64, 81, 121, 169}
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Jr Antalan Mar 7 '17 at 7:24
  • 1
    $\begingroup$ @JrAntalan instead of selecting from all integers we generate a sequece of perfect squares and then do your filtering. $\endgroup$ – Kuba Mar 7 '17 at 7:26
  • $\begingroup$ Ah, I got it now. Thanks @Kuba $\endgroup$ – Jr Antalan Mar 7 '17 at 10:41
4
$\begingroup$

Perhaps:

Select[Range[2, 250], 
 Divisible[# - 1, DivisorSigma[1, #] - #] && 
   Mod[Length@Divisors[#], 2] == 1 &]
$\endgroup$
  • $\begingroup$ Where is 36? :) $\endgroup$ – yode Mar 7 '17 at 7:13
  • $\begingroup$ @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. $\endgroup$ – ubpdqn Mar 7 '17 at 7:16
  • $\begingroup$ 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. $\endgroup$ – Jr Antalan Mar 7 '17 at 7:18
  • $\begingroup$ And thank you again. $\endgroup$ – Jr Antalan Mar 7 '17 at 7:18
  • $\begingroup$ @JrAntalan FactorInteger/@result where result is your desired list. $\endgroup$ – ubpdqn Mar 7 '17 at 7:20
0
$\begingroup$
Select[Range[2, 250], EvenQ[Last[Internal`PerfectPower[#]]] &]

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

$\endgroup$
  • $\begingroup$ Thanks @yode. Indeed the code works. $\endgroup$ – Jr Antalan Mar 7 '17 at 7:14
  • $\begingroup$ 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. $\endgroup$ – Jr Antalan Mar 7 '17 at 7:16
  • $\begingroup$ @JrAntalan FactorInteger $\endgroup$ – yode Mar 7 '17 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.