# Narrowing down loop to only print if certain conditions are satisfied

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?
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.
• What do you mean by print? – Rohit Namjoshi Mar 10 '19 at 1:57
• 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 – argamon Mar 10 '19 at 1:58
• Use Select to only keep the items you want. Like this: Select[Table[yourstuff],IntegerQ[Sqrt[#[]]]&] 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. – Bill Mar 10 '19 at 2:23
• For the first part, do you mean Table[{i, Sqrt[7 i + 4], Mod[DivisorSigma[1, 7 i + 4], 47]}, {i, 200}]? – Roman Mar 10 '19 at 2:40
• 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. – Roman Mar 10 '19 at 2:44

Select[

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$$...