|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.rubato.math.arith.NumberTheory
public final class NumberTheory
Various number theoretic functions.
Method Summary | |
---|---|
static int |
divideMod(int x,
int y,
int n)
Divide x by y modulo n . |
static int |
exgcd(int x,
int y,
int[] res)
The extended Euclidean algorithm. |
static int |
gcd(int x,
int y)
The greatest common divisor of two integers. |
static int |
inverseMod(int x,
int n)
Returns an integer y such that x * y = 1 mod n . |
static boolean |
isPrime(int n)
Returns true iff n is a prime integer. |
static int |
lcm(int x,
int y)
The least common multiple of x and y. |
static int |
mod(int x,
int n)
Returns x mod n . |
static int |
powerMod(int x,
int n,
int p)
Raises x to the n -th power modulo p . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static int gcd(int x, int y)
public static int exgcd(int x, int y, int[] res)
res
- is an integer array that will contain two values such that:
res[0]*x + res[1]*y = gcd(x,y)
public static int lcm(int x, int y)
public static int mod(int x, int n)
x
mod n
.
n
- the modulus
x
mod n
, always non-negative.public static int divideMod(int x, int y, int n) throws ZeroDivisorException
x
by y
modulo n
.
n
- the modulus of the division
ZeroDivisorException
- if gcd(y,n) != 1public static int inverseMod(int x, int n) throws ZeroDivisorException
y
such that x
* y
= 1 mod n
.
x
- the integer to be invertedn
- the modulus of the division
ZeroDivisorException
- if gcd(x,p) != 1public static int powerMod(int x, int n, int p) throws ZeroDivisorException
x
to the n
-th power modulo p
.
ZeroDivisorException
- if n < 0 and gcd(x,p) != 1public static boolean isPrime(int n)
n
is a prime integer.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |