Bernoulli numbers: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: added/changed comments and whitespace, simplified some statements, optimized some functions. |
m →{{header|C++}}: works with |
||
Line 769: | Line 769: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{Works with|C++11}} |
|||
=== Using Boost | C++11 === |
|||
{{libheader|boost}} |
{{libheader|boost}} |
||
<lang cpp> |
<lang cpp>/** |
||
/** |
|||
* Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 |
* Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 |
||
* Apple LLVM version 9.1.0 (clang-902.0.39.1) |
* Apple LLVM version 9.1.0 (clang-902.0.39.1) |
||
Line 781: | Line 778: | ||
*/ |
*/ |
||
#include < |
#include <boost/multiprecision/cpp_int.hpp> // 1024bit precision |
||
#include < |
#include <boost/rational.hpp> // Rationals |
||
#include < |
#include <iostream> // std::cout |
||
#include < |
#include <iostream> // formatting |
||
#include <vector> // Container |
|||
#include <boost/multiprecision/cpp_int.hpp> //1024bit precision |
|||
⚫ | |||
rational bernoulli(size_t n) { |
|||
⚫ | |||
⚫ | |||
for (size_t m = 0; m <= n; m++) { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
for(size_t m=0;m<=n;m++){ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
int main() { |
int main() { |
||
for(size_t n = 0; n <= 60;n+=n>=2?2:1){ |
for (size_t n = 0; n <= 60; n += n >= 2 ? 2 : 1) { |
||
auto b = |
auto b = bernoulli(n); |
||
std::cout << "B("<<std::right<<std::setw(2)<<n<<") = "; |
std::cout << "B(" << std::right << std::setw(2) << n << ") = "; |
||
std::cout << std::right<<std::setw(44)<<b.numerator(); |
std::cout << std::right << std::setw(44) << b.numerator(); |
||
std::cout << " / " << b.denominator() <<std::endl; |
std::cout << " / " << b.denominator() << std::endl; |
||
} |
} |
||
return 0; |
return 0; |
||
⚫ | |||
⚫ | |||
⚫ | |||
{{out}} |
{{out}} |
||
<pre> |
<pre> |