Sage Sandbox

This is just a sandbox for you to work in, if you’d like. Be aware that there is no way to save your work except to cut and paste it elsewhere.

Some common commands:

  • Mod(a,n) computes the residue of a modulo n.  If you need to do a giant exponent, put it outside, like Mod(a,n)^e so the computer does it sensibly.
  • gcd(a,b) computes the gcd of a and b.
  • xgcd(a,b) computes the extended euclidean algorithm of a and b (i.e. it outputs the solution to the linear Diophantine equation $ax+by=gcd(a,b)$).
  • primitive_root(p) will give a primitive root modulo p.
  • next_prime(n) will compute the first prime after n (e.g. $n+1$, $n+2$ etc.)
  • is_prime(n) will return True if n is prime, and false otherwise.
  • factor(n) will display a factorization of n.
  • euler_phi(n) will compute the Euler phi (totient) function of n.
  • randint(n,m) will give a random integer between n and m inclusive.