Mathematical Functions
Copyright (C) by Satoshi Tomabechi 1996,1997,2001
All rights reserved.
- abs : absolute value
- acos : arc cosine
- agmpi : pi by arithmetic and geometric mean
- amod : least residue
- APR : primality test
- APRCL : primality test
- asin : arc sine
- atan : arc tangent
- ceil : ceil functions
- Combination : number of combinatios
- conj : conjugate of complex number
- cos : cosine
- cosh : hyperbolic cosine
- cubrt : cubic root
- divide : Eulidean division
- egcd : Euclid extended
- Euler : Euler's constant
- Even : eveness test
- eulerphi : Euler's phi-function
- exp : exponential function
- factorial : factorial
- floor : floor function
- gcd : greatest common divisor
- gamma : gamma function
- gammaln : logarithmic gamma function
- icubrt : integral part of cubic root
- ilog2 : integral part of logarithm with base 2
- imag : imaginary part of complex number
- Int : round a real number to integer
- inverse : inverse
- invmodp : inverse in Z/pZ
- irandom : random number
- isqrt : intger part of square root
- Kronecker: Kronecker symbol
- len : bit length
- len10: number of digits as a decimal number
- log : logarithm
- Moebius : Moebius function
- mod : residue
- mod a*b mod p
- nearInt : nearest integer
- nextprm : next prime
- Odd
- pi :
- power : power of integer
- power: power modulo p
- power: power of real number
- prm : return the n-th prime
- prmdiv : return the smallest divisor
- prmdiv : return the smallest divisor
- Proth : primality test by Proth's theorem
- Rabin : probablisitic primality test
- round : round a number
- SetPrecision : change default precision
- sign : sign
- sin : sine
- sinh : hyperbolic sine
- sqrt : square root modulo p
- sqrt : sqaure root
- square : square
- Swap : exchange two numbres
- tan : tangent
- Val2 : valuation at primes 2
- operator >> : shift to the right
- operator << : shift to the left
- operator~() : negation <<
Mint abs(const Mint& x) source Mint.hpp
Fint abs(Fint& x) source Fint.hpp
Fint abs(Complex& x) source cabs.cpp
[function] return the absolute value of x.
TOP
Fint acos(Fint& x) source sincos.cpp
[function] arc sine
TOP
Fint agmpi(int precision) source agmpi.cpp
[function] compute pi by Legendre-Gauss' arithmetic-geometric mean
[related] chudnov,raman_pi
TOP
Mint amod(const Mint& a,const Mint& p)
int amod(const Mint& a,const int p) source Mint.hpp
long amod(const Mint& a,const long p ) ; source Mint.hpp
unsigned long amod(const Mint& a,const unsigned long p) source Mint.hpp
long amod(long a,long b) source amodl.cpp
[function] return the residue whose absolute value is least.
i.e. the integer r satisfing n=q*p + r 0<= |r| <|p|/2
[related]
Mint Mint::operator^(const Mint& p)
amod(n,p)=n^p
operator^,operator^=
TOP
bool APR(const Mint& N) source APR.cpp
[function] primarity test by Adleman-Pomerance-Rumely using Gauss sum
[return value] true : prime
false : not prime
[related] APRCL,Proth,Rabin
TOP
bool APRCL(const Mint& N) source APRCl.cpp
[function] primality test by Adleman-Pomerance-Rumely method
improved by Cohen-Lenstra
[return value] true : prime
false : nor prime
[related] APR , Proth
TOP
Fint asin(Fint& x) source sincos.cpp
[function]
TOP
Mint Combination(unsigend long n,unsigned long k) source combi.cpp
[function] n!/(k!(n-k)!)
TOP
Fint atan(Fint& x) source atan.cpp
Complex atan(Complex& x) source complex.cpp
[function] arctangent (-pi/2,pi/2]
Fint atan(Fint& x,Fint& y) source atan.cpp
[function] arc tangent (-pi/2,pi/2]
TOP
Mint ceil(Fint& x) source ceil.cpp
[function] reutrn the integer m such that x <=m < x+1.
[ex] ceil(1.5)=2
ceil(1.0)=1
ceil(-1.5)=-1
TOP
Complex conj(Complex& c)
[function] return the conjugate number of complex number.
given a+ib, return a-ib (i2=-1).
TOP
Fint cos(Fint& x) source sincos.cpp
[function] cosine radian
TOP
Fint cosh(Fint& x) source sinhcosh.cpp
[function] hyperbolic cosine i.e. (exp(x)+exp(-x))/2
TOP
Fint cubrt(Fint& x) source fcubrt.cpp
[function] compute the cubic root of x
by Newton-Paphson method
TOP
void divide(const Mint& a,const Mint& b,Mint& q,Mint& r) source dividem.cpp
void divide(const long a,const long b,long& q,long& r) source dividel.cpp
[function] quotient and remainder by Euclidean division
The sign of remainder r is as same as sign of dividend a.
TOP
Mint egcd(const Mint& a,const Mint& b,Mint& u,Mint& v) (mint.hpp)
long egcd(long a,long b,long& u,long& v) source(egcdl.cpp)
[function] return the greatest common divisor gcd(a,b)
and compute the integers which satisfy gcd(a,b)=u*a+ v*b
[related] Mint& isEGCD(Mint& a,Mint& b,Mint& u,Mint& v) (egcdm.cpp)
TOP
Fint Euler(int precision) source euler.cpp
[function] compute Euler's constant up to specified precision.
the table of Berboulli numbers is needed in curent folder.
by Euler-Mclaurin method.
TOP
bool Even(const Mint& n) (MintFuncs.hpp)
[function] true : n is even.
false : n is odd
[related] Odd
TOP
unsigned long eulerphi(unsigned long n) source eulerphi.cpp
[function] Euler's phi-function ( Euler totient ).
the number of positive integer which is less than n
and coprime to n
#{ k | gcd(k,n)=1, 1<=k<=n}
[ex] eulerphi(p)=p-1 if p is prime.
eulerphi(4)=2
TOP
Fint exp(Fint& x) source exp.cpp
[function] exponential
TOP
Mint factorial(unsinged long n) source fact.cpp
[function] factorial n!=1*2*...*n
[ex] factorial(0)=1 factorial(1)=1 factorial(10)=3628800
TOP
Mint floor(Fint& x) source floor.cpp
[function] [x]
return the integer m such that x-1<m<=x
[ex] floor(1.5)=2
floor(1.0)=1
floor(-1.5)=-1
TOP
Fint gamma(Fint& x) source gamma.cpp
[function] gamma function
if x is an integer, then compute the factorial x!
if x is not an integer, then compute exp(gammaln(x))
TOP
Fint gammaln(Fint& x) source gammaln.cpp
[function] logarithmic gamma function
TOP
Mint gcd(const Mint& a,const Mint& b) (mint.hpp)
long gcd(const long gcd,const long gcd) source(gcdl.cpp)
unsigned long gcd(unsigned long a,unsigned long b) (gcdul.cpp)
[function] return the greatest common divisor.
gcd(a,b) is always positive.
[related] Mint& isGCD(Mint& a,Mint& b) (gcdm.cpp)
TOP
Mint icubrt(Mint& n) source icubrt.cpp
[function] Given n>0, return the integer s s.t. s3<=n <(s+1)3
if n is negative, return -icubrt(-n)
[ex] icubrt(3)=1
icubrt(10)=2
icubrt(-1001)=-10
TOP
long ilog2(Mint& a) source ilog2m.cpp
long ilog2(long a) source ilog2l.cpp
[function]
given a,return the n s.t.2n<=|a|<2n+1
if a=0, return -1
[ex]
a=0 ilog2(a)=-1
a=1 ilog2(a)=0
a=2 ilog2(a)=1
a=3 ilog2(a)=1
a=4 ilog2(a)=2
TOP
Fint& imag(Complex& c)
[function] the imaginary part of complex number
[related] real
TOP
Mint Int(Fint& f)
[function] round a real number to integer by truncating fractional part.
[ex]
f=1.5 Int(f)=1
f=-1.5 Int(f)=-1
TOP
Fint inverse(Fint& f) source inverse.cpp
[function] inverse 1/f
TOP
Mint invmodp(Mint& n,Mint& p) source invmodpm.cpp
long invmodp(long n,long p) source invmodpl.cpp
unsigned long invmodp(const unsigned long n,const unsigned long p)
unsigned long invmodp(const long n,const unsigned long p)
[function]
return 1/n mod p i.e. m such that n*m = 1 mod p if n is prime to p,
0 if n is not prime to p
TOP
unsigned long irandom(unsigned long& n) source irandom.cpp
[function] generate random number
forumula n*1664525+1013904223 mod 232
n must be not zero.
TOP
Mint isqrt(Mint& n) source isqrt.cpp
[function] return the integer s such that s2<= n < (s+1)2
[return value] the integral part of square root
[ex] isqrt(3)=1
isqrt(4)=2
isqrt(10)=3
TOP
long Kronecker(Mint a,Mint p) source ksmbl.cpp
long Kronecker(long a.long p) source ksmbll.cpp
[function] Kronecker symbol
(a/p)= 1 x2=a mod p has a solution,
-1 x2=a mod p has no solution,
0 gcd(a,p)!=1
TOP
long len(Mint& n) source Mint.hpp
long len(long n) source IntFuncs.hpp
[function] number of bits needed to represent the number n as binary number
len(n)=ilog2(n)+1
[ex] len(0)=0
len(1)=1
len(2)=2
len(2n)=n+1
[related] ilog2
TOP
long len10(cosnt Mint& n) source len10.hpp
[function] number of digits in decimal representation
[ex] len10(0)=0
len10(1)=1
len10(10)=2
len10(10n)=n+1
TOP
Fint log(Fint& x) source log.cpp
Complex log(Complex& c)
[function] natural logarithm
TOP
int Moebius(unsigned long n) source Moebius.cpp
[function] Moebius function
return value : 0 n contains a square divisor
-1 number of divisors of n is odd
1 number of divisors of n is even
[ex] Moebius(10)=1 10=2*5
Moebius(105)=-1 105=3*5*7
Moebius(100)=0 100=10^2
TOP
Mint mod(Mint& n,Mint& p)
int mod(Mint& n,int p)
long mod(Mint& n,const long p)
unsigned long mod(Mint& n,const unsigned long p)
long mod(const long n,const long p)
unsigned long mod(const long n,const unsigned long p) source modlul.cpp
[function] the non-negative least residue of n modulo p
i.e. r such that n = q*p + r 0<= r < |p|
[related]
Mint Mint::operator&(Mint& p)
mod(n,p)=n&p
TOP
Mint mod(long a,long b,long p) source mulmodl.cpp
[function] a*b mod p
TOP
Mint nearInt(const Mint& a,const Mint& b) source nearIntf.cpp
Mint nearInt(const Fint& f) source nearIntf.cpp
[function] return the nearest integer to a/b (f).
[ex] nearInt(0.3)=0
nearInt(-0.3)=0
TOP
unsigned long nextprm(ubsigned long n) source nextprm.cpp
[function] return the smallest prime that is greater than n.
[ex] nextprm(1)=2
nextprm(2)=3
nextprm(3)=5
nextprm(4)=5
TOP
bool Odd(Mint& n)
[function] true : n is odd
false : n is even
[related] Even
TOP
Fint pi(int precison)
[function] pi. computed up to specified precision
if precision is not specified, computed in default precision.
by Chudnovsky's formula.
TOP
Mint power(Mint& a,unsigned long n) source ipower.cpp
Fint power(Mint n,Fint f) source fpower.cpp
[function] compute n-th power of a: an
by repeated squaring.
exponent must be non-negative.
TOP
Mint power(Mint& a,Mint& n,Mint& p) source powmod.cpp
long power(long x,unsigned long n,long p) source powmodl.cpp
[function] compute an mod p
if exponent n is negative, compute (1/a mod p)n mod p
TOP
Fint power(Fint a,Fint f) source fpower.cpp
[function] compute af
TOP
unsigned long prm(unsigned long n) source prm.cpp
[function] n-th prime
[ex] prm(0)=1
prm(1)=2
prm(2)=3
prm(3)=5
prm(4)=7
TOP
unsigned long prmdiv(Mint& n) source prmdiv.cpp
[function] return the smallest divisor of n
0 if n has no small divisor with <2^20
1 if n is prime.
TOP
unsigned long prmdiv(unsigned long n) source prmdivul.cpp
[function] return the smallest divisor of n
if n is prime, then return 1.
[ex] prmdiv(100)=2
prmdiv(103)=1
TOP
int Proth(const Mint& N) source Proth.cpp
[function] primality test by Proth theorem
[return value]
1 : N is prime
0 : N is not prime
-1 : N is not an integer to which Proth theorem cannot apply.
m>1 : N is prime and a divisor of m-th Fermat number
TOP
bool Rabin(const Mint& N) source Rabin.cpp
[function] probabilistic primaly test by Miller-Rabin method
[return value]
false : is not prime.
true : may be prime
[related] APRCL , Proth
TOP
Fint& real(Complex& c)
[function] return the real part of complex number
[related] imag
TOP
Fint round(Fint& f,int n)
[function] round a rela number at ni-th digit place.
i.e given f>0, let g be f*232n + 0.5
round g to the nearest integer k
finally return k*2-32n
-round(-f,n) for f<0
TOP
int SetPrecision(const int _precision)
[function] change precision
[return value] previous precision
TOP
int sign(Mint& a)
int sign(Fint& a)
[function] return the sign of number
1 : if a is positive
0 : if a is zero
-1 : if a is negative
TOP
Fint sin(Fint& x) source sincos.cpp
[function] sine
TOP
Fint sinh(const Fint& x) source sinhcosh.cpp
[function] hyperbolic sine i.e. (exp(x)-exp(-x))/2
TOP
Mint sqrt(const Mint a,const Mint& p) source sqrt.cpp
long sqrt(const long a,const long p) source sqrtmodl.cpp
[function] if a is a quadratic residue modulo prime p,
return the square root of x2=a mod p.
The function does not check whether a,p satisfies (a/p)=1.
You should check whether (a/p)=1 before using this function.
[related] Kronecker
TOP
Fint sqrt(Fint& x) source sqrtf.cpp
[function] compute the positive square root of x.
TOP
Mint square(const Mint& a) source square.cpp
[function] compute the square of a.
for large numbers, function "square" is faster than computing a*a, as usual
TOP
void Swap(Mint& a,Mint& b) source Swapm.cpp
[function] exchange a and b
faster than the following way:
Mint temp;
temp=a;
a=b ;
b=temp;
TOP
Fint tan(Fint& x) source tan.cpp
[function] tangent compute as sin(x)/cos(x).
TOP
int Val2(const Mint& n)
[function] the largest exponent m s.t. 2m | n
-1 if n=0
[ex] Val2(1)=0
Val2(n2k)=k n: odd
TOP
Mint Mint::operator>>(const long n)
Mint Mint::operator>>=(const long n)
Fint Fint::operator>>(const long n)
Fint Fint::operator>>=(const long n)
[function] shift an number to the right by n-bits
if n is negative, shift to the left by (-n)-bits
[related] shift operator<<
TOP
Mint Mint::operator<<(const long n)
Mint Mint::operator<<=(const long n)
Fint Fint::operator<<(const long n)
Fint Fint::operator<<=(const long n)
[function] shift a number to the left by n-bits.
if n is negative, shift to right to (-n)-bits
[related] shift operator >>
TOP
Mint& Mint::operator~()
Fint& Fint::operator~()
[function] reverse the sign of number
a=-a ;
TOP