I have the following code

Table[Riffle[Mod[{i, DivisorSigma[1, 7 i + 4]}, 47], Sqrt[7 i + 4]], {i, 200}]

and it works perfectly fine. There are two modifications which I would like help with:

  1. How can I print the index i without it being Mod[47]?
  2. This part is more complicated. I am trying to narrow down the loop to only print if the following conditions are satisfied: a) The number is actually a perfect square & b) The number 7 i + 4 is congruent to 0 mod 47. So unless those two conditions are satisfied I do not want it to print.
  • $\begingroup$ What do you mean by print? $\endgroup$ – Rohit Namjoshi Mar 10 '19 at 1:57
  • $\begingroup$ I guess I mean that I do not need a table necesarilly, I just want to know when it satisfies conditions a & b . If it does not satisfy them then I do not need to see any output $\endgroup$ – argamon Mar 10 '19 at 1:58
  • $\begingroup$ Use Select to only keep the items you want. Like this: Select[Table[yourstuff],IntegerQ[Sqrt[#[[2]]]]&] which will only keep the items where the square root of the second item in each pair is an integer. Then you can think how to add another condition to also limit it to satisfy your condition a. $\endgroup$ – Bill Mar 10 '19 at 2:23
  • 2
    $\begingroup$ For the first part, do you mean Table[{i, Sqrt[7 i + 4], Mod[DivisorSigma[1, 7 i + 4], 47]}, {i, 200}]? $\endgroup$ – Roman Mar 10 '19 at 2:40
  • 2
    $\begingroup$ I think there are not many numbers $i$ that are perfect squares and at the same time satisfy $7i+4=0$ mod 47. Check: Select[Range[10^6]^2, Mod[7 # + 4, 47] == 0 &] returns nothing. $\endgroup$ – Roman Mar 10 '19 at 2:44

I think you may be looking for something like the following:

 Array[{#, #^2} &, 10000000],
 Divisible[7 Last[#] + 4, 47] &

This generates the first $10^7$ perfect squares, associated with the corresponding integer $i$ of which they are a square, then tests whether the expression $7\ i^2+4$ is divisible by 47.

The problem is, there are no such numbers up to $i=10^7$...


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.