# Modular Arithmetic Question using Sage

Hey forumgoers, just have a question using Sage. I am having trouble with a few questions asked to me, heres the questions, how do can you compute (n-1)! mod n for n < 100. Find a formula relating the number of idempotents in Zsubn with the number of distinct prime factors that n has.

An element a in Z(subn) is a square if there is some b element of Z(subn) such that a^2=b. Find the number of squares in Z(sub p^n).

edit retag close merge delete

Please post what you have tried and maybe a specific question about what you have tried. Some helpful resources are in the tutorial, for example, http://sagemath.org/doc/tutorial/tour_assignment.html This sounds like it might be a homework problem. We'd be doing you a huge disservice if it is and we just handed you the answer.

( 2010-11-09 17:01:47 -0500 )edit

Sort by » oldest newest most voted

I agree with Jason on most of these. The only one of these which is worthy is the (n-1)! one. I feel like it's ok for me to give Sage commands to do this, though not in one fell swoop - s/he'll still have to put it together.

Keep in mind, though, Mathstudent2010, that your instructor is almost certainly NOT looking for this! Instead a more theoretical result is probably in mind. In particular, although your instructor might find it okay to find a pattern using a computer program, they almost certainly will not appreciate a 'proof' of it using the program. You'll have to discover that part for yourself.

In general, if you want to just see the output of something for a certain number of integers, I recommend

for n in [1..100]:
print do_this_thing(n)


This isn't the best longterm, but it provides immediate feedback. This is called a loop.

Secondly, the factorial function is easy - for instance, 10! is factorial(10).

Finally, you can get modular arithmetic as well. For instance, 25 modulo 7 is mod(25,7). Put it all together and you should be able to get an answer, possibly showing you a pattern - but not a proof.

more

Jason and Kcrisman, thank you for your reply, help and suggestions. Here is what I have been doing: sage: for n in [1..100]: ....: print mod(factorial(n-1), n) ....: 0 1 2 2 4 0 6 0 0 0 10 0 12 0 0 0 16 0 18 0 0 0 22 0 0 0 0 0 28 0 30 0 0 0 0 0 36 0 0 0 40 0 42 0 0 0 46 0 0 0 0 0 52 0 0 0 0 0 58 0 60 0 0 0 0 0 66 0 0 0 70 0 72 0 0 0 0 0 78 0 0 0 82 0 0 0 0 0 88 0 0 0 0 0 0 0 96 0 0 0

( 2010-11-16 06:26:38 -0500 )edit

I think I am going down the right path. Any input would be nice.

( 2010-11-16 06:33:11 -0500 )edit

Yup, you figured out how to get Sage to do this for you - congratulations! The rest is mathematics - observing patterns, verifying them, proving them. Good luck!

( 2010-11-17 05:40:55 -0500 )edit