jukaukor

jannentaxicab.cpp

Jun 21st, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. //Jannen koodi taxicab.cpp
  2. #define NDEBUG
  3. //#include <boost/cstdfloat.hpp>
  4. #include <iostream>
  5. #include <chrono>
  6. #include <cmath>
  7.  
  8. #include <boost/multiprecision/cpp_int.hpp>
  9. #include <boost/multiprecision/cpp_bin_float.hpp>
  10. #include <boost/multiprecision/float128.hpp>
  11. #include <boost/multiprecision/mpfr.hpp>
  12.  
  13. namespace mp = boost::multiprecision;
  14.  
  15. void taxi_cab(mp::uint128_t tc)
  16. {
  17. mp::uint128_t raja = (mp::cbrt(tc.convert_to<mp::float128>()) + 0.5).convert_to<mp::uint128_t>();
  18.  
  19. std::cout << raja << "\n";
  20.  
  21. mp::uint128_t temp = 0;
  22.  
  23. mp::uint128_t i = 0;
  24. mp::uint128_t j = 0;
  25.  
  26. for ( i = 1 ; i < raja ; i++ )
  27. {
  28. mp::uint128_t iii = i*i*i;
  29.  
  30. //mp::float128 f = (tc-iii).convert_to<mp::float128>();
  31.  
  32. //j = (mp::round(mp::cbrt(f))).convert_to<mp::uint128_t>();
  33.  
  34. double f = (tc-iii).convert_to<double>();
  35.  
  36. j = mp::uint128_t(std::round(std::cbrt(f)));
  37.  
  38. if (iii + j*j*j == tc)
  39. {
  40. if (i == temp)
  41. break;
  42.  
  43. std::cout << i << " " << j << "\n";
  44.  
  45. temp = j;
  46. }
  47. }
  48. }
  49.  
  50. int main()
  51. {
  52. auto t0 = std::chrono::steady_clock::now();
  53.  
  54. //taxi_cab(mp::uint128_t("24153319581254312065344"));
  55. taxi_cab(mp::uint128_t("24153319581254312065344"));
  56.  
  57. auto t1 = std::chrono::steady_clock::now();
  58.  
  59. std::chrono::duration<double> dur = t1 - t0;
  60.  
  61. std::cout << dur.count() << "\n";
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment