# 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[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.
• 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
• 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
• Still much faster: FreeQ[Mod[7*Range[10^7]^2, 47], 43] takes only 0.5 seconds, and Lookup[Counts[Mod[7*Range[10^7]^2, 47]], 43, 0] only 0.2 seconds. Surprising that the latter is faster than the former. – Roman Mar 10 '19 at 8:19

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