Ask Your Question
1

Using powermod in a loop

asked 6 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 6 years ago

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 !

Preview: (hide)
link
0

answered 6 years ago

slelievre gravatar image

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

Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 6 years ago

Seen: 652 times

Last updated: Sep 14 '18