- /* tools.h by K.Tsuru */
- /******************************
- auxiliary tools for SN library
- Their .cpp files are in the directory "sn32/src/af"
- *******************************/
- #ifndef TOOLS_H
- #define TOOLS_H
-
- // typedef of uint, ushort, etc.
- #ifndef TYPEDEF_H
- #include "typedef.h"
- #endif // TYPEDEF_H
-
- #ifndef NC_BLOCK_H
- #include "ncblock.h"
- #endif // NC_BLOCK_H
-
- #ifndef SNBLOCK_H
- #include "snblock.h"
- #endif // SNBLOCK_H
-
- #ifndef MATH_TEMPLATE_H
- #include "mathtp.h" // to use "sameSign()"
- #endif // MATH_TEMPLATE_H
-
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- /**************************************************************
- Return a value k which satisfies a condition sz<=k (k = 2^n).
- **************************************************************/
- uint ceilpow2(uint sz);
-
- /**************************************************************
- Return a value n which satisfies a condition p<= 2^n.
- e.g. p = 5 --> n = 3
- ***************************************************************/
- uint howpow2(uint p);
-
- /*****************************************
- It returns how many digits "x" has in radix "r" i.e.
- a value x which satisfies a condition x<= r^n.
- e.g. x = 25, r = 10 --> n = 2
- *****************************************/
- uint howdigsrdx(long x, long r);
-
- /*****************************************
- SNumber sub-function
- It converts "long x" to "f[]" in radix R.
- and returns "n".
- x = f[n-1]*R^(n-1) + ... +f[1]*R + f[0]
- *****************************************/
- int rdxconv(int *f, long x, long R);
-
- /**************************************************************
- bisection method
- bisectn.cpp
- It solves an equation f(x) = 0 in the region of [a, b].
- **************************************************************/
- double bisection(double a, double b, double tolerance, double (*f)(double));
-
- /**************************************************************
- It returns how many terms are necessary to evaluate exp(x)
- in the precision.
- parameter log10x : Prease give log10(x).
- "expupto.cpp"
- ***************************************************************/
- long upToExpSeries(long precision, double log10x);
-
- /********************************************************
- The rough estimate value for the number of prime under N.
- pi(x) ~ x/ln(x) (Prime number theorem)
- *********************************************************/
- ulong PrimeNumberUnder(ulong N);
- /****************************************
- It makes the prime table between 2 and n
- using the sieve of Eratosthenes.
- Returns the size of pf[].
- *****************************************/
- ulong MakePrimeTable(NCBlock <ulong>& table, const ulong upTo);
-
- /*********************************
- factorization into prime factor
- N! = a^p b^q c^r ...x y z
- **********************************/
- #ifndef STRUCT_PRIMFACTOR
- #define STRUCT_PRIMFACTOR
- struct primeFactor {
- ulong prime;
- int power;
- };
- #endif // STRUCT_PRIMFACTOR
- int FactorialIntoPrimeFactor(ulong N, SNBlock <primeFactor>& pf);
- // Factorial n <= 12 since version 2.30
- inline ulong factUL(ulong n) {
- ulong r = n--;
- for( ; n ; n--) r *= n;
- return r;
- }
- // n! double version n <= 20
- inline double factD(ulong n) {
- double r = n--;
- for( ; n ; n--) r *= n;
- return r;
- }
- // double version of nCk
- const long nMax_combD = 48L; // maximum value of n
- double combD(ulong n, ulong k);
-
- // It returns the present time in string "hh:mm:ss".
- string WhatTimeNow();
- // Split large number file
- int SplitLargeFile(const char* largeFileName, const long fileLineUnit, const char* outFNameFormat);
- /*
- When press y | Y key return 1
- n | N key return 0
- usage : cerr << "Quit ? (Y/N)"; YesOrNo();
- */
- int YesOrNo();
-
- #endif //TOOLS_H
tools.h : last modifiled at 2017/07/16 15:58:34(3,759 bytes)
created at 2016/04/11 11:18:59
The creation time of this html file is 2017/10/11 16:07:52 (Wed Oct 11 16:07:52 2017).