0
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Marius Ladegård Meyer Sep 18 '16 at 12:34
  • $\begingroup$ @MariusLadegårdMeyer, I am asking how to make a function/module/block that does all of the above for any odd n in Mathematica. $\endgroup$ – myg Sep 18 '16 at 12:43
  • $\begingroup$ Then read the docs for Module :) It should be self explainatory. $\endgroup$ – Marius Ladegård Meyer Sep 18 '16 at 12:45
  • $\begingroup$ @MariusLadegårdMeyer, I have read them but am finding it difficult to implement it in this case. Can you help me do the application? $\endgroup$ – myg Sep 18 '16 at 13:07
1
$\begingroup$

As requested in comments, a demo:

algo[n_?OddQ, k_?OddQ] /; k < n := Module[{x, y},
  x = Table[PowerMod[2 a + 1, (n + 1)/2, n], {a, 1, k}];
  y = Table[2 a + 1, {a, 1, k}];
  Select[Mod[x, y], # == 0 &]
  ]

The character ± does not have any built-in meaning in Mathematica, so I chose + in the demo. You will need to implement some decision on whether to use + or - yourself :)

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.

$\endgroup$

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.