fork download
  1. /// PI Challenge
  2. /// rirosi . net / plus2 /
  3.  
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <cstdio>
  7. #include <cmath>
  8. #include <vector>
  9. #include <algorithm>
  10. using namespace std;
  11.  
  12. #define double long double
  13. using t = pair<double, long long>;
  14.  
  15. double simurate(long long p) {
  16. double r = 3.141592653589793L;
  17. while (p) {
  18. if (p&1) r-=2.0L; else r=r*r;
  19. p>>=1;
  20. }
  21. return r;
  22. }
  23.  
  24. int main()
  25. {
  26. double x = 3.141592653589793L;
  27.  
  28. t sel = { x, 0 } ;
  29. for (long long p = 1LL << 25; p > 0; p--) {
  30. auto r = simurate(p);
  31. if (r*r <= sel.first*sel.first) sel = {r, p};
  32. }
  33.  
  34. printf("%0.60llf\n", x);
  35. printf("%0.60llf\n", sel.first);
  36. printf("%0.60llf\n", sel.first - x);
  37. while (sel.second>0) {
  38. printf("%lld", sel.second & 1);
  39. sel.second >>= 1;
  40. }
  41. }
  42.  
Success #stdin #stdout 3.92s 15232KB
stdin
Standard input is empty
stdout
3.141592653589792999988331012595210722793126478791236877441406
0.000000000000000000000000000000000000000000000000000000000000
-3.141592653589792999988331012595210722793126478791236877441406
10100000001011