# Putting some calculations together to form an algorithm

Considering these below where n is an odd number, k is also an odd number less than n:

In[56]:= Table[PowerMod[2 a + 1, (n ± 1)/2, n], {a, 1, k}];
In[57]:= Table[2 a + 1, {a, 1, k}];
In[58]:= Mod[%56, %57];
In[59]:= Select[%, # == 0 &]
Out[59]= {0}


How do I put all these together into an algorithm that will work for any number n?

• Are you asking how to make a function/module/block that does all of the above for any odd n? Or how to extend it to even n as well? – Marius Ladegård Meyer Sep 18 '16 at 12:34
• @MariusLadegårdMeyer, I am asking how to make a function/module/block that does all of the above for any odd n in Mathematica. – myg Sep 18 '16 at 12:43
• Then read the docs for Module :) It should be self explainatory. – Marius Ladegård Meyer Sep 18 '16 at 12:45
• @MariusLadegårdMeyer, I have read them but am finding it difficult to implement it in this case. Can you help me do the application? – myg Sep 18 '16 at 13:07

algo[n_?OddQ, k_?OddQ] /; k < n := Module[{x, y},

Also, you do realize that Select[list, # == 0 &] will always output a list of 0's right? I don't know how useful that is... If you want to know how many are zeros, use Count[list, 0] instead.