1. /* tools.h by K.Tsuru */
  2. /******************************
  3. auxiliary tools for SN library
  4. Their .cpp files are in the directory "sn32/src/af"
  5. *******************************/
  6. #ifndef TOOLS_H
  7. #define TOOLS_H
  8. // typedef of uint, ushort, etc.
  9. #ifndef TYPEDEF_H
  10. #include "typedef.h"
  11. #endif // TYPEDEF_H
  12. #ifndef NC_BLOCK_H
  13. #include "ncblock.h"
  14. #endif // NC_BLOCK_H
  15. #ifndef SNBLOCK_H
  16. #include "snblock.h"
  17. #endif // SNBLOCK_H
  18. #ifndef MATH_TEMPLATE_H
  19. #include "mathtp.h" // to use "sameSign()"
  20. #endif // MATH_TEMPLATE_H
  21. #include <math.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. /**************************************************************
  25. Return a value k which satisfies a condition sz<=k (k = 2^n).
  26. **************************************************************/
  27. uint ceilpow2(uint sz);
  28. /**************************************************************
  29. Return a value n which satisfies a condition p<= 2^n.
  30. e.g. p = 5 --> n = 3
  31. ***************************************************************/
  32. uint howpow2(uint p);
  33. /*****************************************
  34. It returns how many digits "x" has in radix "r" i.e.
  35. a value x which satisfies a condition x<= r^n.
  36. e.g. x = 25, r = 10 --> n = 2
  37. *****************************************/
  38. uint howdigsrdx(long x, long r);
  39. /*****************************************
  40. SNumber sub-function
  41. It converts "long x" to "f[]" in radix R.
  42. and returns "n".
  43. x = f[n-1]*R^(n-1) + ... +f[1]*R + f[0]
  44. *****************************************/
  45. int rdxconv(int *f, long x, long R);
  46. /**************************************************************
  47. bisection method
  48. bisectn.cpp
  49. It solves an equation f(x) = 0 in the region of [a, b].
  50. **************************************************************/
  51. double bisection(double a, double b, double tolerance, double (*f)(double));
  52. /**************************************************************
  53. It returns how many terms are necessary to evaluate exp(x)
  54. in the precision.
  55. parameter log10x : Prease give log10(x).
  56. "expupto.cpp"
  57. ***************************************************************/
  58. long upToExpSeries(long precision, double log10x);
  59. /********************************************************
  60. The rough estimate value for the number of prime under N.
  61. pi(x) ~ x/ln(x) (Prime number theorem)
  62. *********************************************************/
  63. ulong PrimeNumberUnder(ulong N);
  64. /****************************************
  65. It makes the prime table between 2 and n
  66. using the sieve of Eratosthenes.
  67. Returns the size of pf[].
  68. *****************************************/
  69. ulong MakePrimeTable(NCBlock <ulong>& table, const ulong upTo);
  70. /*********************************
  71. factorization into prime factor
  72. N! = a^p b^q c^r ...x y z
  73. **********************************/
  74. #ifndef STRUCT_PRIMFACTOR
  75. #define STRUCT_PRIMFACTOR
  76. struct primeFactor {
  77. ulong prime;
  78. int power;
  79. };
  80. #endif // STRUCT_PRIMFACTOR
  81. int FactorialIntoPrimeFactor(ulong N, SNBlock <primeFactor>& pf);
  82. // Factorial n <= 12 since version 2.30
  83. inline ulong factUL(ulong n) {
  84. ulong r = n--;
  85. for( ; n ; n--) r *= n;
  86. return r;
  87. }
  88. // n! double version n <= 20
  89. inline double factD(ulong n) {
  90. double r = n--;
  91. for( ; n ; n--) r *= n;
  92. return r;
  93. }
  94. // double version of nCk
  95. const long nMax_combD = 48L; // maximum value of n
  96. double combD(ulong n, ulong k);
  97. // It returns the present time in string "hh:mm:ss".
  98. string WhatTimeNow();
  99. // Split large number file
  100. int SplitLargeFile(const char* largeFileName, const long fileLineUnit, const char* outFNameFormat);
  101. /*
  102. When press y | Y key return 1
  103. n | N key return 0
  104. usage : cerr << "Quit ? (Y/N)"; YesOrNo();
  105. */
  106. int YesOrNo();
  107. #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).