Ask Your Question

Using powermod in a loop

asked 2018-09-13 07:16:32 -0500

jds9973 gravatar image

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?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2018-09-13 07:54:35 -0500

tmonteil gravatar image

The 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 !

edit flag offensive delete link more

answered 2018-09-13 19:04:13 -0500

slelievre gravatar image

Using pow(a, b, c) instead of a.powermod(b, c) should work.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2018-09-13 07:16:32 -0500

Seen: 22 times

Last updated: Sep 13