Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array> // array
- #include <cstdio> // printf
- #include <cmath> // floor
- #include <cppcoro/generator.hpp>
- cppcoro::generator<double> gen()
- {
- auto [q, r, t, k, n, l] = std::array<double,6>
- {1, 0, 1, 1, 3, 3};
- for ( ; ; ) {
- if (4*q+r-t < n*t) {
- co_yield n;
- auto nr = 10*(r-n*t);
- n = floor( (10*(3*q+r))/t )-10*n;
- q *= 10;
- r = nr;
- }
- else {
- auto nr = (2*q+r)*l;
- auto nn = floor( (q*(7*k)+2+(r*l))/(t*l) );
- q *= k;
- t *= l;
- l += 2;
- k += 1;
- n = nn;
- r = nr;
- }
- }
- }
- int main()
- {
- auto digit_limit = 45;
- for (auto digit : gen() ) {
- printf("%.0lf", digit);
- if (--digit_limit) { continue; } else { break; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement