Sha256: 0e6f12a7ef4fce1a40a4a43f87f91628ac1c8dfe9efff57720579e3b08c57006

Contents?: true

Size: 277 Bytes

Versions: 4

Compression:

Stored size: 277 Bytes

Contents

# coding: utf-8
class Integer
  def quadratic_residue?(p)
    residue? p, 2
  end

  def cubic_residue?(p)
    coprime?(p) and residue? p, 3
  end

  def reciprocal
    self ** -1
  end

  private
  def residue?(p, e=1)
    (1...p).any?{|x| (x**e).modulo(p) == self}
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
numb-0.186.0 lib/numb/reciprocity.rb
numb-0.185.0 lib/numb/reciprocity.rb
numb-0.184.0 lib/numb/reciprocity.rb
numb-0.181.0 lib/numb/reciprocity.rb