ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 14 Sep 2018 02:04:13 +0200Using powermod in a loophttps://ask.sagemath.org/question/43658/using-powermod-in-a-loop/Sorry if this question is naive, I have just started using Sage. I was playing around with Carmichael numbers and wanted to produce a list of a^n mod n for various values of a.
I thought the code
for k in range(2,5):
j = k.powermod(n,n)
would do what I wanted. But I get the error message 'int' object has no attribute 'powermod'
Any suggestions? Thu, 13 Sep 2018 14:16:32 +0200https://ask.sagemath.org/question/43658/using-powermod-in-a-loop/Answer by tmonteil for <p>Sorry if this question is naive, I have just started using Sage. I was playing around with Carmichael numbers and wanted to produce a list of a^n mod n for various values of a.</p>
<p>I thought the code
for k in range(2,5):
j = k.powermod(n,n)</p>
<p>would do what I wanted. But I get the error message 'int' object has no attribute 'powermod'</p>
<p>Any suggestions? </p>
https://ask.sagemath.org/question/43658/using-powermod-in-a-loop/?answer=43659#post-id-43659The problem is that `range` produces Python `int`, not Sage integers, hence the `powermod` method is not avaiable. Just replace `range` with `srange` and it shoud work !
Thu, 13 Sep 2018 14:54:35 +0200https://ask.sagemath.org/question/43658/using-powermod-in-a-loop/?answer=43659#post-id-43659Answer by slelievre for <p>Sorry if this question is naive, I have just started using Sage. I was playing around with Carmichael numbers and wanted to produce a list of a^n mod n for various values of a.</p>
<p>I thought the code
for k in range(2,5):
j = k.powermod(n,n)</p>
<p>would do what I wanted. But I get the error message 'int' object has no attribute 'powermod'</p>
<p>Any suggestions? </p>
https://ask.sagemath.org/question/43658/using-powermod-in-a-loop/?answer=43665#post-id-43665Using `pow(a, b, c)` instead of `a.powermod(b, c)` should work.Fri, 14 Sep 2018 02:04:13 +0200https://ask.sagemath.org/question/43658/using-powermod-in-a-loop/?answer=43665#post-id-43665